Skip to content
Snippets Groups Projects
Commit 8b669406 authored by Debolskiy Andrey's avatar Debolskiy Andrey :bicyclist_tone5:
Browse files

Added CalcBrkPoint function to the main class, so far works as intended

parent dfa5f4c7
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -18,15 +18,82 @@ namespace MES_Wind
{
public partial class frmMain : Form
{
[Export("Shell", typeof(ContainerControl))]
private static ContainerControl Shell;
#region "Control variables"
double distThreshold = 500;
#endregion
public frmMain()
{
InitializeComponent();
if (DesignMode) return;
Shell = this;
appManager1.LoadExtensions();
}
#region
/// <summary>
/// This function is used to check if the segment of powerline is broken.
/// Based on the given line segment's start and endpoint, it divides the line on
/// suitable subsegments defined by threshold length - dThreshold
/// </summary>
/// <param name="startX">Line segement's start X point</param>
/// <param name="startY">Line segement's start Y point</param>
/// <param name="endX">Line segement's end X point</param>
/// <param name="endY">Line segement's end Y point</param>
/// <param name="dThreshold">Line segment length threshold</param>
/// <param name="Uwind_raster">Raster Layer for progmostic wind X coord</param>
/// <param name="Vwind_raster">Raster Layer for progmostic wind Y coord</param>
/// <returns>List of booleans with coordinates if any of them are true, line is broken</returns>
/// <remarks></remarks>
#endregion
public List<CheckPoint> CalcBrkPoint(double startX, double startY, double endX, double endY, double dThreshold, IMapRasterLayer Uwind_raster, IMapRasterLayer Vwind_raster)
{
List<CheckPoint> lineCheckPoint = new List<CheckPoint>();
double uwind = 0;
double vwind = 0;
double umod = 0;
double anglewind = 0;
double distance = Math.Sqrt((endX - startX) * (endX - startX) + (endY - startY) * (endY - startY));
double distpropD = distance / dThreshold;
int distpropI = Convert.ToInt32(distpropD);
double curX = startX;
double curY = startY;
CheckPoint chkpnt = new CheckPoint();
if (distpropI > 1)
{
double constXdiff = (endX - startX) / distpropI;
double constYdiff = (endY - startY) / distpropI;
for (int j = 1; j < distpropI + 1; j++)
{
if (j == 1)
{
curX = startX + constXdiff / 2;
curY = startY + constXdiff / 2;
}
else
{
curX = curX + constXdiff;
curY = curY + constYdiff;
}
Coordinate coords = new Coordinate(curX,curY);
RcIndex rowColumnU = Uwind_raster.DataSet.Bounds.ProjToCell(coords);
uwind = Uwind_raster.DataSet.Value[rowColumnU.Row, rowColumnU.Column];
RcIndex rowColumnV = Vwind_raster.DataSet.Bounds.ProjToCell(coords);
vwind = Vwind_raster.DataSet.Value[rowColumnV.Row, rowColumnV.Column];
umod = Math.Sqrt(uwind*uwind + vwind*vwind);
anglewind = Math.Atan2(uwind,vwind);
chkpnt.X = curX;
chkpnt.Y = curY;
chkpnt.Ifbroken = false;
lineCheckPoint.Add(chkpnt);
}
}
return lineCheckPoint;
}
private void bntLoadWindX_Click(object sender, EventArgs e)
{
......@@ -104,15 +171,33 @@ namespace MES_Wind
// new FeatureSet for resulting broken powerlines
IFeatureSet brklineSet = new FeatureSet(FeatureType.Line);
DataTable dt = pwlineSet.DataTable;
List<CheckPoint> fullCheckList = new List<CheckPoint>();
foreach (IFeature feature in pwlineSet.Features)
{
List<CheckPoint> lineCheckList = new List<CheckPoint>();
LineString linestr = feature.BasicGeometry as LineString;
if (linestr != null)
{ // case if powerline consists of one line
// get coordinates list
IList<Coordinate> points = linestr.Coordinates;
IFeature brklineFeature = brklineSet.AddFeature(linestr);
//get associated attributes
DataRow featureData = feature.DataRow;
int id = int.Parse(featureData["PW_ID"].ToString());
int year = int.Parse(featureData["Year"].ToString());
// cycle throw all points in line
for (int i=1; i< points.Count; i++)
{
List<CheckPoint> segmentCheckList = new List<CheckPoint>();
double x1 = points[i - 1].X;
double y1 = points[i - 1].Y;
double x2 = points[i].X;
double y2 = points[i].Y;
segmentCheckList = CalcBrkPoint(x1,y1,x2,y2,distThreshold,u_rasterLayer,v_rasterLayer);
lineCheckList.AddRange(segmentCheckList);
}
fullCheckList.AddRange(lineCheckList);
brklineFeature.CopyAttributes(feature);
}
else
......@@ -141,11 +226,21 @@ namespace MES_Wind
}
}
public class PathPoint
{
public double X1;
public double Y1;
public double X2;
public double Y2;
public double Distance;
public double Uwind;
public double Vwind;
public int Year;
}
public class CheckPoint
{
public double X;
public double Y;
public double Distance;
public double RstValue;
public bool Ifbroken;
}
}
No preview for this file type
No preview for this file type
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="STATISTICS_MAXIMUM">10</MDI>
<MDI key="STATISTICS_MEAN">2.2305699982413</MDI>
<MDI key="STATISTICS_MINIMUM">-4.1609997749329</MDI>
<MDI key="STATISTICS_STDDEV">3,03557538986206</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="STATISTICS_MAXIMUM">10</MDI>
<MDI key="STATISTICS_MEAN">3.4739124851488</MDI>
<MDI key="STATISTICS_MINIMUM">0</MDI>
<MDI key="STATISTICS_STDDEV">2,81997513771057</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment