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

added xml comments and refactoring of app code

parent a3abd430
No related branches found
No related tags found
No related merge requests found
...@@ -35,11 +35,6 @@ ...@@ -35,11 +35,6 @@
this.map1 = new DotSpatial.Controls.Map(); this.map1 = new DotSpatial.Controls.Map();
this.splitter1 = new System.Windows.Forms.Splitter(); this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.sdmDataOperations = new DotSpatial.Controls.SpatialDockManager();
this.gbOperations = new System.Windows.Forms.GroupBox();
this.btnViewAttributeTable = new System.Windows.Forms.Button();
this.dgvAttributeTable = new System.Windows.Forms.DataGridView();
this.bntLoadWindX = new System.Windows.Forms.Button();
this.btnLoadWindY = new System.Windows.Forms.Button(); this.btnLoadWindY = new System.Windows.Forms.Button();
this.btnCalcStress = new System.Windows.Forms.Button(); this.btnCalcStress = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.sdmMapLegend)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.sdmMapLegend)).BeginInit();
...@@ -47,12 +42,6 @@ ...@@ -47,12 +42,6 @@
this.sdmMapLegend.Panel2.SuspendLayout(); this.sdmMapLegend.Panel2.SuspendLayout();
this.sdmMapLegend.SuspendLayout(); this.sdmMapLegend.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.sdmDataOperations)).BeginInit();
this.sdmDataOperations.Panel1.SuspendLayout();
this.sdmDataOperations.Panel2.SuspendLayout();
this.sdmDataOperations.SuspendLayout();
this.gbOperations.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvAttributeTable)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// appManager1 // appManager1
...@@ -67,7 +56,7 @@ ...@@ -67,7 +56,7 @@
// //
// sdmMapLegend // sdmMapLegend
// //
this.sdmMapLegend.Dock = System.Windows.Forms.DockStyle.Top; this.sdmMapLegend.Dock = System.Windows.Forms.DockStyle.Fill;
this.sdmMapLegend.Location = new System.Drawing.Point(0, 0); this.sdmMapLegend.Location = new System.Drawing.Point(0, 0);
this.sdmMapLegend.Name = "sdmMapLegend"; this.sdmMapLegend.Name = "sdmMapLegend";
// //
...@@ -78,7 +67,7 @@ ...@@ -78,7 +67,7 @@
// sdmMapLegend.Panel2 // sdmMapLegend.Panel2
// //
this.sdmMapLegend.Panel2.Controls.Add(this.map1); this.sdmMapLegend.Panel2.Controls.Add(this.map1);
this.sdmMapLegend.Size = new System.Drawing.Size(782, 234); this.sdmMapLegend.Size = new System.Drawing.Size(782, 360);
this.sdmMapLegend.SplitterDistance = 260; this.sdmMapLegend.SplitterDistance = 260;
this.sdmMapLegend.TabControl1 = null; this.sdmMapLegend.TabControl1 = null;
this.sdmMapLegend.TabControl2 = null; this.sdmMapLegend.TabControl2 = null;
...@@ -87,7 +76,7 @@ ...@@ -87,7 +76,7 @@
// legend1 // legend1
// //
this.legend1.BackColor = System.Drawing.Color.White; this.legend1.BackColor = System.Drawing.Color.White;
this.legend1.ControlRectangle = new System.Drawing.Rectangle(0, 0, 260, 234); this.legend1.ControlRectangle = new System.Drawing.Rectangle(0, 0, 260, 360);
this.legend1.Dock = System.Windows.Forms.DockStyle.Fill; this.legend1.Dock = System.Windows.Forms.DockStyle.Fill;
this.legend1.DocumentRectangle = new System.Drawing.Rectangle(0, 0, 187, 428); this.legend1.DocumentRectangle = new System.Drawing.Rectangle(0, 0, 187, 428);
this.legend1.HorizontalScrollEnabled = true; this.legend1.HorizontalScrollEnabled = true;
...@@ -100,7 +89,7 @@ ...@@ -100,7 +89,7 @@
this.legend1.ResetOnResize = false; this.legend1.ResetOnResize = false;
this.legend1.SelectionFontColor = System.Drawing.Color.Black; this.legend1.SelectionFontColor = System.Drawing.Color.Black;
this.legend1.SelectionHighlight = System.Drawing.Color.FromArgb(((int)(((byte)(215)))), ((int)(((byte)(238)))), ((int)(((byte)(252))))); this.legend1.SelectionHighlight = System.Drawing.Color.FromArgb(((int)(((byte)(215)))), ((int)(((byte)(238)))), ((int)(((byte)(252)))));
this.legend1.Size = new System.Drawing.Size(260, 234); this.legend1.Size = new System.Drawing.Size(260, 360);
this.legend1.TabIndex = 0; this.legend1.TabIndex = 0;
this.legend1.TabStop = false; this.legend1.TabStop = false;
this.legend1.Text = "legend1"; this.legend1.Text = "legend1";
...@@ -125,7 +114,7 @@ ...@@ -125,7 +114,7 @@
this.map1.ProjectionModeReproject = DotSpatial.Controls.ActionMode.Prompt; this.map1.ProjectionModeReproject = DotSpatial.Controls.ActionMode.Prompt;
this.map1.RedrawLayersWhileResizing = false; this.map1.RedrawLayersWhileResizing = false;
this.map1.SelectionEnabled = true; this.map1.SelectionEnabled = true;
this.map1.Size = new System.Drawing.Size(518, 234); this.map1.Size = new System.Drawing.Size(518, 360);
this.map1.TabIndex = 0; this.map1.TabIndex = 0;
this.map1.ZoomOutFartherThanMaxExtent = false; this.map1.ZoomOutFartherThanMaxExtent = false;
// //
...@@ -139,7 +128,6 @@ ...@@ -139,7 +128,6 @@
// //
// panel1 // panel1
// //
this.panel1.Controls.Add(this.sdmDataOperations);
this.panel1.Controls.Add(this.sdmMapLegend); this.panel1.Controls.Add(this.sdmMapLegend);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(114, 0); this.panel1.Location = new System.Drawing.Point(114, 0);
...@@ -147,67 +135,6 @@ ...@@ -147,67 +135,6 @@
this.panel1.Size = new System.Drawing.Size(782, 360); this.panel1.Size = new System.Drawing.Size(782, 360);
this.panel1.TabIndex = 1; this.panel1.TabIndex = 1;
// //
// sdmDataOperations
//
this.sdmDataOperations.Dock = System.Windows.Forms.DockStyle.Fill;
this.sdmDataOperations.Location = new System.Drawing.Point(0, 234);
this.sdmDataOperations.Name = "sdmDataOperations";
this.sdmDataOperations.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// sdmDataOperations.Panel1
//
this.sdmDataOperations.Panel1.Controls.Add(this.gbOperations);
//
// sdmDataOperations.Panel2
//
this.sdmDataOperations.Panel2.Controls.Add(this.dgvAttributeTable);
this.sdmDataOperations.Size = new System.Drawing.Size(782, 126);
this.sdmDataOperations.SplitterDistance = 55;
this.sdmDataOperations.TabControl1 = null;
this.sdmDataOperations.TabControl2 = null;
this.sdmDataOperations.TabIndex = 1;
//
// gbOperations
//
this.gbOperations.Controls.Add(this.btnViewAttributeTable);
this.gbOperations.Dock = System.Windows.Forms.DockStyle.Fill;
this.gbOperations.Location = new System.Drawing.Point(0, 0);
this.gbOperations.Name = "gbOperations";
this.gbOperations.Size = new System.Drawing.Size(782, 55);
this.gbOperations.TabIndex = 0;
this.gbOperations.TabStop = false;
this.gbOperations.Text = "Operations";
//
// btnViewAttributeTable
//
this.btnViewAttributeTable.Location = new System.Drawing.Point(7, 22);
this.btnViewAttributeTable.Name = "btnViewAttributeTable";
this.btnViewAttributeTable.Size = new System.Drawing.Size(188, 23);
this.btnViewAttributeTable.TabIndex = 0;
this.btnViewAttributeTable.Text = "View Attribute table";
this.btnViewAttributeTable.UseVisualStyleBackColor = true;
this.btnViewAttributeTable.Click += new System.EventHandler(this.btnViewAttributeTable_Click);
//
// dgvAttributeTable
//
this.dgvAttributeTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvAttributeTable.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgvAttributeTable.Location = new System.Drawing.Point(0, 0);
this.dgvAttributeTable.Name = "dgvAttributeTable";
this.dgvAttributeTable.RowTemplate.Height = 24;
this.dgvAttributeTable.Size = new System.Drawing.Size(782, 67);
this.dgvAttributeTable.TabIndex = 0;
//
// bntLoadWindX
//
this.bntLoadWindX.Location = new System.Drawing.Point(12, 74);
this.bntLoadWindX.Name = "bntLoadWindX";
this.bntLoadWindX.Size = new System.Drawing.Size(96, 46);
this.bntLoadWindX.TabIndex = 2;
this.bntLoadWindX.Text = "Load Xwind";
this.bntLoadWindX.UseVisualStyleBackColor = true;
this.bntLoadWindX.Click += new System.EventHandler(this.bntLoadWindX_Click);
//
// btnLoadWindY // btnLoadWindY
// //
this.btnLoadWindY.Location = new System.Drawing.Point(12, 147); this.btnLoadWindY.Location = new System.Drawing.Point(12, 147);
...@@ -235,7 +162,6 @@ ...@@ -235,7 +162,6 @@
this.ClientSize = new System.Drawing.Size(896, 360); this.ClientSize = new System.Drawing.Size(896, 360);
this.Controls.Add(this.btnCalcStress); this.Controls.Add(this.btnCalcStress);
this.Controls.Add(this.btnLoadWindY); this.Controls.Add(this.btnLoadWindY);
this.Controls.Add(this.bntLoadWindX);
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.splitter1); this.Controls.Add(this.splitter1);
this.Name = "frmMain"; this.Name = "frmMain";
...@@ -245,12 +171,6 @@ ...@@ -245,12 +171,6 @@
((System.ComponentModel.ISupportInitialize)(this.sdmMapLegend)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.sdmMapLegend)).EndInit();
this.sdmMapLegend.ResumeLayout(false); this.sdmMapLegend.ResumeLayout(false);
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.sdmDataOperations.Panel1.ResumeLayout(false);
this.sdmDataOperations.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.sdmDataOperations)).EndInit();
this.sdmDataOperations.ResumeLayout(false);
this.gbOperations.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgvAttributeTable)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
...@@ -260,15 +180,10 @@ ...@@ -260,15 +180,10 @@
private DotSpatial.Controls.AppManager appManager1; private DotSpatial.Controls.AppManager appManager1;
private System.Windows.Forms.Splitter splitter1; private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button bntLoadWindX;
private DotSpatial.Controls.SpatialDockManager sdmMapLegend; private DotSpatial.Controls.SpatialDockManager sdmMapLegend;
private DotSpatial.Controls.Legend legend1; private DotSpatial.Controls.Legend legend1;
private DotSpatial.Controls.Map map1; private DotSpatial.Controls.Map map1;
private System.Windows.Forms.Button btnLoadWindY; private System.Windows.Forms.Button btnLoadWindY;
private System.Windows.Forms.Button btnCalcStress; private System.Windows.Forms.Button btnCalcStress;
private DotSpatial.Controls.SpatialDockManager sdmDataOperations;
private System.Windows.Forms.GroupBox gbOperations;
private System.Windows.Forms.DataGridView dgvAttributeTable;
private System.Windows.Forms.Button btnViewAttributeTable;
} }
} }
\ No newline at end of file
...@@ -82,8 +82,8 @@ namespace MES_Wind ...@@ -82,8 +82,8 @@ namespace MES_Wind
private void btnLoadWindY_Click(object sender, EventArgs e) private void btnLoadWindY_Click(object sender, EventArgs e)
{ {
string curDir = Environment.CurrentDirectory; string curDir = Environment.CurrentDirectory;
string path_to_tests = "\\MES_test_new\\"; string pathToTests = "\\MES_test_new\\";
string file_path = curDir + path_to_tests; string file_path = curDir + pathToTests;
map1.AddLayer(file_path+"u_test.asc"); map1.AddLayer(file_path+"u_test.asc");
map1.AddLayer(file_path + "v_test.asc"); map1.AddLayer(file_path + "v_test.asc");
...@@ -93,51 +93,16 @@ namespace MES_Wind ...@@ -93,51 +93,16 @@ namespace MES_Wind
map1.AddLayer(file_path + "powerlines.shp"); map1.AddLayer(file_path + "powerlines.shp");
map1.AddLayer(file_path + "powerstations.shp"); map1.AddLayer(file_path + "powerstations.shp");
map1.ZoomToMaxExtent(); map1.ZoomToMaxExtent();
}
private void btnViewAttributeTable_Click(object sender, EventArgs e)
{
//Declare a datatable
DataTable dt = null;
if (map1.GetLineLayers().Count() > 0)
{
MapLineLayer pwlLayer = default(MapLineLayer);
pwlLayer = (MapLineLayer)map1.GetLineLayers()[0];
if (pwlLayer == null)
{
MessageBox.Show("The layer is not a line layer.");
}
else
{
//Get the shapefile's attribute table to our datatable dt
dt = pwlLayer.DataSet.DataTable;
//Set the datagridview datasource from datatable dt
dgvAttributeTable.DataSource = dt;
}
}
else
{
MessageBox.Show("Please add a layer to the map.");
}
} }
private void btnCalcStress_Click(object sender, EventArgs e) private void btnCalcStress_Click(object sender, EventArgs e)
{
try
{ {
//extract prognostic u layer //extract prognostic u layer
IMapRasterLayer u_rasterLayer = default(IMapRasterLayer); IMapRasterLayer uRasterLayer = default(IMapRasterLayer);
IMapRasterLayer v_rasterLayer = default(IMapRasterLayer); IMapRasterLayer vRasterLayer = default(IMapRasterLayer);
IMapRasterLayer clim5_rasterLayer = default(IMapRasterLayer); IMapRasterLayer clim5RasterLayer = default(IMapRasterLayer);
IMapRasterLayer clim10_rasterLayer = default(IMapRasterLayer); IMapRasterLayer clim10RasterLayer = default(IMapRasterLayer);
IMapRasterLayer clim15_rasterLayer = default(IMapRasterLayer); IMapRasterLayer clim15RasterLayer = default(IMapRasterLayer);
if (map1.GetRasterLayers().Count() == 1) if (map1.GetRasterLayers().Count() == 1)
{ {
...@@ -145,11 +110,11 @@ namespace MES_Wind ...@@ -145,11 +110,11 @@ namespace MES_Wind
return; return;
} }
//this makes raster layers list in map1 ordered! //this makes raster layers list in map1 ordered!
u_rasterLayer = map1.GetRasterLayers()[0]; uRasterLayer = map1.GetRasterLayers()[0];
v_rasterLayer = map1.GetRasterLayers()[1]; vRasterLayer = map1.GetRasterLayers()[1];
clim5_rasterLayer = map1.GetRasterLayers()[2]; clim5RasterLayer = map1.GetRasterLayers()[2];
clim10_rasterLayer = map1.GetRasterLayers()[3]; clim10RasterLayer = map1.GetRasterLayers()[3];
clim15_rasterLayer = map1.GetRasterLayers()[4]; clim15RasterLayer = map1.GetRasterLayers()[4];
//get the powerline line layer //get the powerline line layer
IMapLineLayer pwlLayer = default(IMapLineLayer); IMapLineLayer pwlLayer = default(IMapLineLayer);
...@@ -168,57 +133,52 @@ namespace MES_Wind ...@@ -168,57 +133,52 @@ namespace MES_Wind
IFeatureSet pwpointsSet = pwstLayer.DataSet; IFeatureSet pwpointsSet = pwstLayer.DataSet;
//Start to cast raster to PRM classes //Start to cast raster to PRM classes
// prognostic wind massives first // prognostic wind massives first
List<List<PRMLibrary.PrognosticCell>> prog_wind = new List<List<PRMLibrary.PrognosticCell>>(); List<List<PRMLibrary.PrognosticCell>> prognosticWind = new List<List<PRMLibrary.PrognosticCell>>();
int rcountPrognostic = uRasterLayer.DataSet.NumRows;
PRMLibrary.Coordinate dummy_coord = new PRMLibrary.Coordinate(); int ccountPrognostic = uRasterLayer.DataSet.NumColumns;
Coordinate dummy_rcoord = new Coordinate(); for (int i =0; i< rcountPrognostic; i++)
PRMLibrary.PrognosticCell dummy_prognostic = new PRMLibrary.PrognosticCell(dummy_coord, 0, 0);
int rcount_prog = u_rasterLayer.DataSet.NumRows;
int ccount_prog = u_rasterLayer.DataSet.NumColumns;
for (int i =0; i< ccount_prog; i++)
{ {
List<PRMLibrary.PrognosticCell> prog_wind_row = new List<PRMLibrary.PrognosticCell>(); List<PRMLibrary.PrognosticCell> progWindRow = new List<PRMLibrary.PrognosticCell>();
for (int j =0; j< rcount_prog; j++ ) for (int j =0; j< ccountPrognostic; j++ )
{ {
dummy_prognostic.velocityX = u_rasterLayer.DataSet.Value[j, i]; PRMLibrary.PrognosticCell dummyPrognosticCell = new PRMLibrary.PrognosticCell();
dummy_prognostic.velocityY = v_rasterLayer.DataSet.Value[j, i]; dummyPrognosticCell.velocityX = uRasterLayer.DataSet.Value[j, i];
dummy_rcoord = u_rasterLayer.Bounds.CellCenter_ToProj(j,i); dummyPrognosticCell.velocityY = vRasterLayer.DataSet.Value[j, i];
dummy_coord.X = dummy_rcoord.X; Coordinate dummyRCoords = uRasterLayer.Bounds.CellCenter_ToProj(j,i);
dummy_coord.Y = dummy_rcoord.Y; PRMLibrary.Coordinate cellCoords =new PRMLibrary.Coordinate(dummyRCoords.X,dummyRCoords.Y);
dummy_prognostic.coords = dummy_coord; dummyPrognosticCell.coords = cellCoords;
prog_wind_row.Add(dummy_prognostic); progWindRow.Add(dummyPrognosticCell);
} }
prog_wind.Add(prog_wind_row); prognosticWind.Add(progWindRow);
//prog_wind_row.Clear(); //prog_wind_row.Clear();
} }
//Get cell info and Affine transform coefficients from prognostic wind rasters //Get cell info and Affine transform coefficients from prognostic wind rasters
PRMLibrary.CellSize prog_cell = new PRMLibrary.CellSize(u_rasterLayer.DataSet.CellWidth, u_rasterLayer.DataSet.CellHeight); PRMLibrary.CellSize progcellsize = new PRMLibrary.CellSize(uRasterLayer.DataSet.CellWidth, uRasterLayer.DataSet.CellHeight);
double[] prog_aff = u_rasterLayer.Bounds.AffineCoefficients; double[] prog_aff = uRasterLayer.Bounds.AffineCoefficients;
//Now we create climate raster class //Now we create climate raster class
List<List<PRMLibrary.ClimateCell>> clim_wind = new List<List<PRMLibrary.ClimateCell>>(); List<List<PRMLibrary.ClimateCell>> climWind = new List<List<PRMLibrary.ClimateCell>>();
PRMLibrary.ClimateCell dummy_clim = new PRMLibrary.ClimateCell(dummy_coord, 0, 0, 0); int rowCountClim = clim5RasterLayer.DataSet.NumRows;
int rcount_clim = clim5_rasterLayer.DataSet.NumRows; int columnCountClim = clim5RasterLayer.DataSet.NumColumns;
int ccount_clim = clim5_rasterLayer.DataSet.NumColumns; for (int i = 0; i < rowCountClim; i++)
for (int i = 0; i < ccount_clim; i++)
{ {
List<PRMLibrary.ClimateCell> clim_wind_row = new List<PRMLibrary.ClimateCell>(); List<PRMLibrary.ClimateCell> climWindRow = new List<PRMLibrary.ClimateCell>();
for (int j = 0; j < rcount_clim; j++) for (int j = 0; j < columnCountClim; j++)
{ {
dummy_clim.wind5 = clim5_rasterLayer.DataSet.Value[j, i]; PRMLibrary.ClimateCell dummyClim = new PRMLibrary.ClimateCell();
dummy_clim.wind10 = clim10_rasterLayer.DataSet.Value[j, i] ; // Important: substract 3 to this to get powerlines broken dummyClim.wind5 = clim5RasterLayer.DataSet.Value[j, i];
dummy_clim.wind15 = clim15_rasterLayer.DataSet.Value[j, i]; dummyClim.wind10 = clim10RasterLayer.DataSet.Value[j, i] ; // Important: substract 3 to this to get powerlines broken
dummy_rcoord = clim15_rasterLayer.Bounds.CellCenter_ToProj(j,i); dummyClim.wind15 = clim15RasterLayer.DataSet.Value[j, i];
dummy_coord.X = dummy_rcoord.X; Coordinate dummyCellCoords = clim15RasterLayer.Bounds.CellCenter_ToProj(j,i);
dummy_coord.Y = dummy_rcoord.Y; PRMLibrary.Coordinate dummyClimCoords = new PRMLibrary.Coordinate(dummyCellCoords.X,dummyCellCoords.Y);
dummy_clim.coords = dummy_coord; dummyClim.coords = dummyClimCoords;
clim_wind_row.Add(dummy_clim); climWindRow.Add(dummyClim);
} }
clim_wind.Add(clim_wind_row); climWind.Add(climWindRow);
//clim_wind_row.Clear(); //clim_wind_row.Clear();
} }
//Get cell info and affine transform coeff from climate rasters //Get cell info and affine transform coeff from climate rasters
PRMLibrary.CellSize clim_cell = new PRMLibrary.CellSize(clim5_rasterLayer.DataSet.CellWidth, clim5_rasterLayer.DataSet.CellHeight); PRMLibrary.CellSize climCellsize = new PRMLibrary.CellSize(clim5RasterLayer.DataSet.CellWidth, clim5RasterLayer.DataSet.CellHeight);
double[] clim_aff = clim5_rasterLayer.Bounds.AffineCoefficients; double[] climAffinecoeffs = clim5RasterLayer.Bounds.AffineCoefficients;
// create PRM_line list to pass to PRM_wind from loaded line layer // create PRM_line list to pass to PRM_wind from loaded line layer
List<PRMLibrary.Powerline> powerlinesToPRM = new List<PRMLibrary.Powerline>(); List<PRMLibrary.Powerline> powerlinesToPRM = new List<PRMLibrary.Powerline>();
foreach (IFeature feature in pwlineSet.Features) foreach (IFeature feature in pwlineSet.Features)
...@@ -231,17 +191,17 @@ namespace MES_Wind ...@@ -231,17 +191,17 @@ namespace MES_Wind
dummyline.power = int.Parse(featureData["Power"].ToString()); dummyline.power = int.Parse(featureData["Power"].ToString());
dummyline.pointFromID = int.Parse(featureData["PointFrom"].ToString()); dummyline.pointFromID = int.Parse(featureData["PointFrom"].ToString());
dummyline.pointToID = int.Parse(featureData["PointTo"].ToString()); dummyline.pointToID = int.Parse(featureData["PointTo"].ToString());
LineString ftline = feature.BasicGeometry as LineString; LineString featureline = feature.BasicGeometry as LineString;
dummyline.coords = DotspLinestringToPrm(ftline); dummyline.coords = DotspLinestringToPrm(featureline);
powerlinesToPRM.Add(dummyline); powerlinesToPRM.Add(dummyline);
} }
//create PRM_station list to pass to PRM_wind from loaded point layer //create PRM_station list to pass to PRM_wind from loaded point layer
List<PRMLibrary.PowerStation> powerpointsToPRM = new List<PRMLibrary.PowerStation>(); List<PRMLibrary.PowerStation> powerpointsToPRM = new List<PRMLibrary.PowerStation>();
foreach (IFeature ftpoint in pwpointsSet.Features) foreach (IFeature featurepoint in pwpointsSet.Features)
{ {
PRMLibrary.PowerStation dummystation = new PRMLibrary.PowerStation(); PRMLibrary.PowerStation dummystation = new PRMLibrary.PowerStation();
DataRow featureData = ftpoint.DataRow; DataRow featureData = featurepoint.DataRow;
dummystation.identifier = ftpoint.Fid; dummystation.identifier = featurepoint.Fid;
dummystation.name = featureData["Name"].ToString(); dummystation.name = featureData["Name"].ToString();
dummystation.power = int.Parse(featureData["Power"].ToString()); dummystation.power = int.Parse(featureData["Power"].ToString());
int issr = int.Parse(featureData["IsSource"].ToString()); int issr = int.Parse(featureData["IsSource"].ToString());
...@@ -261,8 +221,8 @@ namespace MES_Wind ...@@ -261,8 +221,8 @@ namespace MES_Wind
} }
} }
dummystation.type = featureData["Type"].ToString(); dummystation.type = featureData["Type"].ToString();
IPoint ftpt = ftpoint.BasicGeometry as IPoint; IPoint featurepointcoords = featurepoint.BasicGeometry as IPoint;
dummystation.coords = DotspPointToPRM(ftpt); dummystation.coords = DotspPointToPRM(featurepointcoords);
powerpointsToPRM.Add(dummystation); powerpointsToPRM.Add(dummystation);
} }
...@@ -270,12 +230,12 @@ namespace MES_Wind ...@@ -270,12 +230,12 @@ namespace MES_Wind
PRMLibrary.Module prmwind = new PRMLibrary.Module(); PRMLibrary.Module prmwind = new PRMLibrary.Module();
prmwind.input.powerLines = powerlinesToPRM; prmwind.input.powerLines = powerlinesToPRM;
prmwind.input.powerStations = powerpointsToPRM; prmwind.input.powerStations = powerpointsToPRM;
prmwind.input.prognosticCells = prog_wind; prmwind.input.prognosticCells = prognosticWind;
prmwind.input.prognosticCellSize = prog_cell; prmwind.input.prognosticCellSize = progcellsize;
prmwind.input.prognosticAffineCoefficients = prog_aff; prmwind.input.prognosticAffineCoefficients = prog_aff;
prmwind.input.climateCells = clim_wind; prmwind.input.climateCells = climWind;
prmwind.input.climateCellSize = clim_cell; prmwind.input.climateCellSize = climCellsize;
prmwind.input.climateAffineCoefficients = clim_aff; prmwind.input.climateAffineCoefficients = climAffinecoeffs;
//Calculate which lines are broken //Calculate which lines are broken
List<PRMLibrary.Powerline> prmBrokenLines = prmwind.brokenPowerLinesAfterCheck(); List<PRMLibrary.Powerline> prmBrokenLines = prmwind.brokenPowerLinesAfterCheck();
prmwind.CheckPower(); prmwind.CheckPower();
...@@ -289,13 +249,6 @@ namespace MES_Wind ...@@ -289,13 +249,6 @@ namespace MES_Wind
//LineSymbolizer symbol = new LineSymbolizer(Color.Red, 3); //LineSymbolizer symbol = new LineSymbolizer(Color.Red, 3);
//brk_info_layer.Symbolizer = symbol; //brk_info_layer.Symbolizer = symbol;
//brk_info_layer.LegendText = "Broken powerlines"; //brk_info_layer.LegendText = "Broken powerlines";
}
catch (Exception ex)
{
MessageBox.Show("Something went wrong");
}
} }
} }
public class CheckPoint public class CheckPoint
......
...@@ -5,48 +5,124 @@ using System.Text; ...@@ -5,48 +5,124 @@ using System.Text;
namespace PRMLibrary namespace PRMLibrary
{ {
/// <summary>
/// Index class for raster lists in list
/// </summary>
public class Index public class Index
{ {
/// <summary>
/// Outer index
/// </summary>
public int Row; public int Row;
/// <summary>
/// Inner index
/// </summary>
public int Col; public int Col;
/// <summary>
/// designated constructor
/// </summary>
/// <param name="Row">row index</param>
/// <param name="Col">column index</param>
public Index(int Row, int Col) public Index(int Row, int Col)
{ {
this.Row = Row; this.Row = Row;
this.Col = Col; this.Col = Col;
} }
/// <summary>
/// default constructor
/// </summary>
public Index() : this(0, 0) { } public Index() : this(0, 0) { }
} }
/// <summary>
/// Coordinate pair
/// </summary>
public class Coordinate public class Coordinate
{ {
/// <summary>
/// easting coordinate
/// </summary>
public double X; public double X;
/// <summary>
/// northing coordinate
/// </summary>
public double Y; public double Y;
/// <summary>
/// designated constructor
/// </summary>
/// <param name="X"></param>
/// <param name="Y"></param>
public Coordinate(double X, double Y) public Coordinate(double X, double Y)
{ {
this.X = X; this.X = X;
this.Y = Y; this.Y = Y;
} }
/// <summary>
/// default constructor
/// </summary>
public Coordinate() : this(0, 0) { } public Coordinate() : this(0, 0) { }
} }
/// <summary>
/// Cell obj for regular prognostic wind field
/// </summary>
public class PrognosticCell public class PrognosticCell
{ {
/// <summary>
/// U - component of wind velocity
/// </summary>
public double velocityX; public double velocityX;
/// <summary>
/// V - component of wind velocity
/// </summary>
public double velocityY; public double velocityY;
/// <summary>
/// Cell center coordinates
/// </summary>
public Coordinate coords; public Coordinate coords;
/// <summary>
/// designated constructor
/// </summary>
/// <param name="coord"> Coordinate pair</param>
/// <param name="vX"> U component</param>
/// <param name="vY"> V component</param>
public PrognosticCell(Coordinate coord, double vX, double vY) public PrognosticCell(Coordinate coord, double vX, double vY)
{ {
this.coords = coord; this.coords = coord;
this.velocityX = vX; this.velocityX = vX;
this.velocityY = vY; this.velocityY = vY;
} }
/// <summary>
/// default constructor
/// </summary>
public PrognosticCell() : this(new Coordinate(), 0, 0) { }
} }
/// <summary>
/// Cell obj for climate wind regular data
/// </summary>
public class ClimateCell public class ClimateCell
{ {
/// <summary>
/// once-in-5-years frequency wind
/// </summary>
public double wind5; public double wind5;
/// <summary>
/// once-in-10-years frequency wind
/// </summary>
public double wind10; public double wind10;
/// <summary>
/// once-in-15-years frequency wind
/// </summary>
public double wind15; public double wind15;
/// <summary>
/// Cell center coordinate pair
/// </summary>
public Coordinate coords; public Coordinate coords;
/// <summary>
/// designated constructor
/// </summary>
/// <param name="coord"></param>
/// <param name="w5"></param>
/// <param name="w10"></param>
/// <param name="w15"></param>
public ClimateCell(Coordinate coord, double w5, double w10, double w15) public ClimateCell(Coordinate coord, double w5, double w10, double w15)
{ {
this.coords = coord; this.coords = coord;
...@@ -54,7 +130,14 @@ namespace PRMLibrary ...@@ -54,7 +130,14 @@ namespace PRMLibrary
this.wind10 = w10; this.wind10 = w10;
this.wind15 = w15; this.wind15 = w15;
} }
/// <summary>
/// default constructor
/// </summary>
public ClimateCell() : this(new Coordinate(), 0, 0, 0) { }
} }
/// <summary>
/// Cell Size parameters
/// </summary>
public struct CellSize public struct CellSize
{ {
public double width; public double width;
...@@ -65,44 +148,126 @@ namespace PRMLibrary ...@@ -65,44 +148,126 @@ namespace PRMLibrary
this.width = wdh; this.width = wdh;
this.height = hgh; this.height = hgh;
} }
} }
/// <summary>
/// power line object
/// </summary>
public class Powerline public class Powerline
{ {
/// <summary>
/// unique id
/// </summary>
public int identifier { get; set; } public int identifier { get; set; }
/// <summary>
/// year of construction
/// </summary>
public int year; public int year;
/// <summary>
/// average height of cable span between two poles, meters
/// </summary>
public double height; public double height;
/// <summary>
/// power kW for switches
/// </summary>
public int power; public int power;
/// <summary>
/// Line vertices coordinate list
/// </summary>
public List<Coordinate> coords { get; set; } public List<Coordinate> coords { get; set; }
/// <summary>
/// assigned powerstation/pole
/// </summary>
public int pointFromID; public int pointFromID;
/// <summary>
/// assigned powerstation/pole
/// </summary>
public int pointToID; public int pointToID;
/// <summary>
/// broken/not broken switch
/// </summary>
public bool isbroken; public bool isbroken;
/// <summary>
/// power on switch
/// </summary>
public bool ison; public bool ison;
private int MissingIdValue = -1;
public Powerline(List<Coordinate> coord, int id, int yer, double h, int pw, bool isbrkn, bool ison, int toID, int fromID) /// <summary>
{ /// designated constructor
this.coords = coord; /// </summary>
/// <param name="coord"></param>
/// <param name="id"></param>
/// <param name="yer"></param>
/// <param name="h"></param>
/// <param name="pw"></param>
/// <param name="isbrkn"></param>
/// <param name="ison"></param>
/// <param name="toID"></param>
/// <param name="fromID"></param>
public Powerline(List<Coordinate> coordinate, int id, int year, double height, int power, bool isbroken, bool ison, int toID, int fromID)
{
this.coords = coordinate;
this.identifier = id; this.identifier = id;
this.year = yer; this.year = year;
this.height = h; this.height = height;
this.power = pw; this.power = power;
this.isbroken = isbrkn; this.isbroken = isbroken;
this.ison = ison; this.ison = ison;
this.pointFromID = fromID; this.pointFromID = fromID;
this.pointToID = toID; this.pointToID = toID;
} }
public Powerline() : base() { } /// <summary>
/// default constructor
/// </summary>
public Powerline() : this(new List<Coordinate>(), -1, 0, 0, 0, false, false, -1, -1) { }
} }
/// <summary>
/// powerstation/pole point class
/// </summary>
public class PowerStation public class PowerStation
{ {
/// <summary>
/// unique id
/// </summary>
public int identifier; public int identifier;
/// <summary>
/// Coordinates
/// </summary>
public Coordinate coords; public Coordinate coords;
/// <summary>
/// station name field
/// </summary>
public string name; public string name;
/// <summary>
/// power, kW
/// </summary>
public int power; public int power;
/// <summary>
/// type of point - trans/pole/endpoint
/// </summary>
public string type; public string type;
/// <summary>
/// is point a source?
/// </summary>
public bool issource; public bool issource;
/// <summary>
/// power on switch
/// </summary>
public bool ison; public bool ison;
/// <summary>
/// asigned powerlines list
/// </summary>
public List<Powerline> linelist; public List<Powerline> linelist;
private int MissingIdValue = -1;
/// <summary>
/// designated constructor
/// </summary>
/// <param name="crds"></param>
/// <param name="id"></param>
/// <param name="stname"></param>
/// <param name="stpower"></param>
/// <param name="sttype"></param>
/// <param name="issource"></param>
/// <param name="ison"></param>
public PowerStation(Coordinate crds, int id, string stname, int stpower, string sttype, bool issource, bool ison) public PowerStation(Coordinate crds, int id, string stname, int stpower, string sttype, bool issource, bool ison)
{ {
this.coords = crds; this.coords = crds;
...@@ -113,7 +278,10 @@ namespace PRMLibrary ...@@ -113,7 +278,10 @@ namespace PRMLibrary
this.issource = issource; this.issource = issource;
this.ison = ison; this.ison = ison;
} }
public PowerStation() : base() { } /// <summary>
/// default constructor
/// </summary>
public PowerStation() : this(new Coordinate(), -1, "", 0, "", false, false) { }
} }
enum FunctionType enum FunctionType
...@@ -124,40 +292,81 @@ namespace PRMLibrary ...@@ -124,40 +292,81 @@ namespace PRMLibrary
FunctionClimate10 = 3, FunctionClimate10 = 3,
FunctionClimate15 = 4 FunctionClimate15 = 4
} }
/// <summary>
/// DTO for input
/// </summary>
public class InputDTO public class InputDTO
{ {
//prognistic raster info /// <summary>
/// prognistic raster info
/// </summary>
public List<List<PrognosticCell>> prognosticCells; public List<List<PrognosticCell>> prognosticCells;
/// <summary>
/// prognostic raster cell info
/// </summary>
public CellSize prognosticCellSize; public CellSize prognosticCellSize;
/// <summary>
/// affine coefficients from prognostic raster projections
/// </summary>
public double[] prognosticAffineCoefficients; public double[] prognosticAffineCoefficients;
//climate raster info /// <summary>
/// climate raster array
/// </summary>
public List<List<ClimateCell>> climateCells; public List<List<ClimateCell>> climateCells;
/// <summary>
/// climate raster cell info
/// </summary>
public CellSize climateCellSize; public CellSize climateCellSize;
/// <summary>
/// affine coefficients from climate raster projection
/// </summary>
public double[] climateAffineCoefficients; public double[] climateAffineCoefficients;
//lines collection /// <summary>
/// lines list
/// </summary>
public List<Powerline> powerLines; public List<Powerline> powerLines;
//station collection /// <summary>
/// stations/poles list
/// </summary>
public List<PowerStation> powerStations; public List<PowerStation> powerStations;
/// <summary>
/// maximum distance for line segment
/// </summary>
public double dist_threshold = 500; public double dist_threshold = 500;
} }
/// <summary>
/// Output DTO
/// </summary>
public class OutputDTO public class OutputDTO
{ {
//broken stations and lines /// <summary>
/// stations list without power
/// </summary>
public List<PowerStation> disabledStations = new List<PowerStation>(); public List<PowerStation> disabledStations = new List<PowerStation>();
/// <summary>
/// broken lines list
/// </summary>
public List<Powerline> disabledLines = new List<Powerline>(); public List<Powerline> disabledLines = new List<Powerline>();
} }
/// <summary>
/// main calculations class
/// </summary>
public class Module public class Module
{ {
/// <summary>
/// Input Data
/// </summary>
public InputDTO input; public InputDTO input;
/// <summary>
/// Output Data
/// </summary>
public OutputDTO output; public OutputDTO output;
//Main function for power graph algorithm /// <summary>
/// Main function for power graph algorithm
/// </summary>
public void CheckPower() public void CheckPower()
{ {
//get the graph //get the graph
...@@ -169,6 +378,7 @@ namespace PRMLibrary ...@@ -169,6 +378,7 @@ namespace PRMLibrary
CheckPowerPointsForStation(pwstation); CheckPowerPointsForStation(pwstation);
} }
} }
//fill output
foreach (Powerline line in input.powerLines) foreach (Powerline line in input.powerLines)
{ {
if (line.isbroken) { if (line.isbroken) {
...@@ -183,7 +393,10 @@ namespace PRMLibrary ...@@ -183,7 +393,10 @@ namespace PRMLibrary
} }
return; return;
} }
//search function for power graph /// <summary>
/// recursive search function for power graph
/// </summary>
/// <param name="sourcepoint"> powered station to search next powered station from</param>
private void CheckPowerPointsForStation(PowerStation sourcepoint) private void CheckPowerPointsForStation(PowerStation sourcepoint)
{ {
if (!sourcepoint.ison) if (!sourcepoint.ison)
...@@ -229,7 +442,9 @@ namespace PRMLibrary ...@@ -229,7 +442,9 @@ namespace PRMLibrary
} }
} }
//preparing powerstations and lists of lines for them to get a graph-like structure /// <summary>
/// preparing powerstations and lists of lines for them to get a graph-like structure
/// </summary>
private void PreparingPowerItems() private void PreparingPowerItems()
{ {
//First we make sure that all the sources are ON //First we make sure that all the sources are ON
...@@ -256,9 +471,13 @@ namespace PRMLibrary ...@@ -256,9 +471,13 @@ namespace PRMLibrary
powerStation.linelist = lines; powerStation.linelist = lines;
} }
} }
/// <summary>
/// function to chec if powerline is broken by wind
/// </summary>
/// <returns>list of broken powerlines</returns>
public List<Powerline> brokenPowerLinesAfterCheck() public List<Powerline> brokenPowerLinesAfterCheck()
{ {
List<Powerline> brklines = new List<Powerline>(); List<Powerline> brokenLines = new List<Powerline>();
// actually there are curves in powerLines // actually there are curves in powerLines
foreach (Powerline powerCurve in input.powerLines) foreach (Powerline powerCurve in input.powerLines)
{ {
...@@ -285,13 +504,23 @@ namespace PRMLibrary ...@@ -285,13 +504,23 @@ namespace PRMLibrary
} }
if (powerCurve.isbroken) if (powerCurve.isbroken)
{ {
brklines.Add(powerCurve); brokenLines.Add(powerCurve);
} }
} }
return brklines; return brokenLines;
} }
/// <summary>
/// Divides the line between two vertices if needed
/// depending on dist_threshold
/// and checks if line is broken by wind in any of midpoints
/// </summary>
/// <param name="coord1">first vertice coordinate</param>
/// <param name="coord2">second vertice </param>
/// <param name="heightLine">height</param>
/// <param name="power">power for climatology switches</param>
/// <returns>true if line is broken false otherwise</returns>
private bool linearLineIsBroken(Coordinate coord1, Coordinate coord2, double heightLine, int power) private bool linearLineIsBroken(Coordinate coord1, Coordinate coord2, double heightLine, int power)
{ {
double distance = Math.Sqrt((coord2.X - coord1.X) * (coord2.X - coord1.X) + (coord2.Y - coord1.Y) * (coord2.Y - coord1.Y)); double distance = Math.Sqrt((coord2.X - coord1.X) * (coord2.X - coord1.X) + (coord2.Y - coord1.Y) * (coord2.Y - coord1.Y));
......
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment