diff --git a/MES_Wind/frmMain.cs b/MES_Wind/frmMain.cs index 1d81b077115a780d5bff7eb5c5692e95f6f90b01..5432ae08bdac0d03926b5afdb1a19e98cbedac1e 100644 --- a/MES_Wind/frmMain.cs +++ b/MES_Wind/frmMain.cs @@ -96,161 +96,182 @@ namespace MES_Wind private void btnCalcStress_Click(object sender, EventArgs e) { - //extract prognostic u layer - IMapRasterLayer uRasterLayer = default(IMapRasterLayer); - IMapRasterLayer vRasterLayer = default(IMapRasterLayer); - IMapRasterLayer clim5RasterLayer = default(IMapRasterLayer); - IMapRasterLayer clim10RasterLayer = default(IMapRasterLayer); - IMapRasterLayer clim15RasterLayer = default(IMapRasterLayer); - - if (map1.GetRasterLayers().Count() == 1) - { - MessageBox.Show("Please add a raster layer"); - return; - } - //this makes raster layers list in map1 ordered! - uRasterLayer = map1.GetRasterLayers()[0]; - vRasterLayer = map1.GetRasterLayers()[1]; - clim5RasterLayer = map1.GetRasterLayers()[2]; - clim10RasterLayer = map1.GetRasterLayers()[3]; - clim15RasterLayer = map1.GetRasterLayers()[4]; - - //get the powerline line layer - IMapLineLayer pwlLayer = default(IMapLineLayer); - if (map1.GetLineLayers().Count() == 0) + const double eps = 0.0001; + const double RasterMissingValue = -9999; + //extract prognostic u layer + IMapRasterLayer uRasterLayer = default(IMapRasterLayer); + IMapRasterLayer vRasterLayer = default(IMapRasterLayer); + IMapRasterLayer clim5RasterLayer = default(IMapRasterLayer); + IMapRasterLayer clim10RasterLayer = default(IMapRasterLayer); + IMapRasterLayer clim15RasterLayer = default(IMapRasterLayer); + if (map1.GetRasterLayers().Count() == 1) + { + MessageBox.Show("Please add a raster layer"); + return; + } + //this makes raster layers list in map1 ordered! + uRasterLayer = map1.GetRasterLayers()[0]; + vRasterLayer = map1.GetRasterLayers()[1]; + clim5RasterLayer = map1.GetRasterLayers()[2]; + clim10RasterLayer = map1.GetRasterLayers()[3]; + clim15RasterLayer = map1.GetRasterLayers()[4]; + //get the powerline line layer + IMapLineLayer pwlLayer = default(IMapLineLayer); + if (map1.GetLineLayers().Count() == 0) + { + MessageBox.Show("Please add powerline shapefile"); + return; + } + pwlLayer = map1.GetLineLayers()[0]; + //copy line layer FeatureSet + IFeatureSet pwlineSet = pwlLayer.DataSet; + //get the powerstations layer + IMapPointLayer pwstLayer = default(IMapPointLayer); + pwstLayer = map1.GetPointLayers()[0]; + // copy point layer FeatureSet + IFeatureSet pwpointsSet = pwstLayer.DataSet; + //Start to cast raster to PRM classes + // prognostic wind massives first + List<List<WindStressPRM.PrognosticCell>> prognosticWind = new List<List<WindStressPRM.PrognosticCell>>(); + int rcountPrognostic = uRasterLayer.DataSet.NumRows; + int ccountPrognostic = uRasterLayer.DataSet.NumColumns; + for (int i =0; i< rcountPrognostic; i++) + { + List<WindStressPRM.PrognosticCell> progWindRow = new List<WindStressPRM.PrognosticCell>(); + for (int j =0; j< ccountPrognostic; j++ ) { - MessageBox.Show("Please add powerline shapefile"); - return; + Coordinate dummyRCoords = uRasterLayer.Bounds.CellCenter_ToProj(i,j); + WindStressPRM.Coordinate cellCoords =new WindStressPRM.Coordinate(dummyRCoords.X,dummyRCoords.Y); + double uValue = uRasterLayer.DataSet.Value[i, j]; + double vValue = vRasterLayer.DataSet.Value[i, j]; + if (Math.Abs(uValue - RasterMissingValue) < eps) { + uValue = Double.NaN; + } + if (Math.Abs(vValue - RasterMissingValue) < eps) { + vValue = Double.NaN; + } + WindStressPRM.PrognosticCell dummyPrognosticCell = new WindStressPRM.PrognosticCell(cellCoords, uValue, vValue); + progWindRow.Add(dummyPrognosticCell); } - pwlLayer = map1.GetLineLayers()[0]; - //copy line layer FeatureSet - IFeatureSet pwlineSet = pwlLayer.DataSet; - //get the powerstations layer - IMapPointLayer pwstLayer = default(IMapPointLayer); - pwstLayer = map1.GetPointLayers()[0]; - // copy point layer FeatureSet - IFeatureSet pwpointsSet = pwstLayer.DataSet; - //Start to cast raster to PRM classes - // prognostic wind massives first - List<List<WindStressPRM.PrognosticCell>> prognosticWind = new List<List<WindStressPRM.PrognosticCell>>(); - int rcountPrognostic = uRasterLayer.DataSet.NumRows; - int ccountPrognostic = uRasterLayer.DataSet.NumColumns; - for (int i =0; i< rcountPrognostic; i++) + prognosticWind.Add(progWindRow); + //prog_wind_row.Clear(); + } + //Get cell info and Affine transform coefficients from prognostic wind rasters + WindStressPRM.CellSize progcellsize = new WindStressPRM.CellSize(uRasterLayer.DataSet.CellWidth, uRasterLayer.DataSet.CellHeight); + double[] prog_aff = uRasterLayer.Bounds.AffineCoefficients; + //Now we create climate raster class + List<List<WindStressPRM.ClimateCell>> climWind = new List<List<WindStressPRM.ClimateCell>>(); + int rowCountClim = clim5RasterLayer.DataSet.NumRows; + int columnCountClim = clim5RasterLayer.DataSet.NumColumns; + for (int i = 0; i < rowCountClim; i++) + { + List<WindStressPRM.ClimateCell> climWindRow = new List<WindStressPRM.ClimateCell>(); + for (int j = 0; j < columnCountClim; j++) { - List<WindStressPRM.PrognosticCell> progWindRow = new List<WindStressPRM.PrognosticCell>(); - for (int j =0; j< ccountPrognostic; j++ ) + Coordinate dummyCellCoords = clim15RasterLayer.Bounds.CellCenter_ToProj(i,j); + WindStressPRM.Coordinate dummyClimCoords = new WindStressPRM.Coordinate(dummyCellCoords.X,dummyCellCoords.Y); + //add or substruct in range 0 - 27 to change what lines will be broken + double clim5 = j; // clim5RasterLayer.DataSet.Value[i, j]; + double clim10 = clim10RasterLayer.DataSet.Value[i, j] - 10; + double clim15 = clim15RasterLayer.DataSet.Value[i, j]; + if (Math.Abs(clim5 - RasterMissingValue) < eps) { - Coordinate dummyRCoords = uRasterLayer.Bounds.CellCenter_ToProj(i,j); - WindStressPRM.Coordinate cellCoords =new WindStressPRM.Coordinate(dummyRCoords.X,dummyRCoords.Y); - WindStressPRM.PrognosticCell dummyPrognosticCell = new WindStressPRM.PrognosticCell(cellCoords, uRasterLayer.DataSet.Value[j, i], vRasterLayer.DataSet.Value[j, i]); - //WindStressPRM.PrognosticCell dummyPrognosticCell = new WindStressPRM.PrognosticCell(cellCoords, 100, 100); - progWindRow.Add(dummyPrognosticCell); + clim5 = Double.NaN; } - prognosticWind.Add(progWindRow); - //prog_wind_row.Clear(); - } - //Get cell info and Affine transform coefficients from prognostic wind rasters - WindStressPRM.CellSize progcellsize = new WindStressPRM.CellSize(uRasterLayer.DataSet.CellWidth, uRasterLayer.DataSet.CellHeight); - double[] prog_aff = uRasterLayer.Bounds.AffineCoefficients; - //Now we create climate raster class - List<List<WindStressPRM.ClimateCell>> climWind = new List<List<WindStressPRM.ClimateCell>>(); - int rowCountClim = clim5RasterLayer.DataSet.NumRows; - int columnCountClim = clim5RasterLayer.DataSet.NumColumns; - for (int i = 0; i < rowCountClim; i++) - { - List<WindStressPRM.ClimateCell> climWindRow = new List<WindStressPRM.ClimateCell>(); - for (int j = 0; j < columnCountClim; j++) + if (Math.Abs(clim10 - RasterMissingValue) < eps) { - Coordinate dummyCellCoords = clim15RasterLayer.Bounds.CellCenter_ToProj(i,j); - WindStressPRM.Coordinate dummyClimCoords = new WindStressPRM.Coordinate(dummyCellCoords.X,dummyCellCoords.Y); - //add or substruct in range 0 - 27 to change what lines will be broken - WindStressPRM.ClimateCell dummyClim = new WindStressPRM.ClimateCell(dummyClimCoords, clim5RasterLayer.DataSet.Value[j, i], clim10RasterLayer.DataSet.Value[j, i] - 10, clim15RasterLayer.DataSet.Value[j, i]); - //WindStressPRM.ClimateCell dummyClim = new WindStressPRM.ClimateCell(dummyClimCoords, 0, 0, 0); - climWindRow.Add(dummyClim); + clim10 = Double.NaN; + } + if (Math.Abs(clim15 - RasterMissingValue) < eps) + { + clim15 = Double.NaN; } - climWind.Add(climWindRow); - //clim_wind_row.Clear(); + WindStressPRM.ClimateCell dummyClim = new WindStressPRM.ClimateCell(dummyClimCoords, clim5, clim10, clim15); + climWindRow.Add(dummyClim); } - //Get cell info and affine transform coeff from climate rasters - WindStressPRM.CellSize climCellsize = new WindStressPRM.CellSize(clim5RasterLayer.DataSet.CellWidth, clim5RasterLayer.DataSet.CellHeight); - double[] climAffinecoeffs = clim5RasterLayer.Bounds.AffineCoefficients; - // create PRM_line list to pass to PRM_wind from loaded line layer - List<WindStressPRM.Powerline> powerlinesToPRM = new List<WindStressPRM.Powerline>(); - foreach (IFeature feature in pwlineSet.Features) + climWind.Add(climWindRow); + //clim_wind_row.Clear(); + } + //Get cell info and affine transform coeff from climate rasters + WindStressPRM.CellSize climCellsize = new WindStressPRM.CellSize(clim5RasterLayer.DataSet.CellWidth, clim5RasterLayer.DataSet.CellHeight); + double[] climAffinecoeffs = clim5RasterLayer.Bounds.AffineCoefficients; + // create PRM_line list to pass to PRM_wind from loaded line layer + List<WindStressPRM.Powerline> powerlinesToPRM = new List<WindStressPRM.Powerline>(); + foreach (IFeature feature in pwlineSet.Features) + { + WindStressPRM.Powerline dummyline = new WindStressPRM.Powerline(); + DataRow featureData = feature.DataRow; + dummyline.Identifier = feature.Fid; + dummyline.Year = int.Parse(featureData["Year"].ToString()); + dummyline.Height = double.Parse(featureData["HeightOffs"].ToString()); + dummyline.Power = int.Parse(featureData["Power"].ToString()); + dummyline.PointFromID = int.Parse(featureData["PointFrom"].ToString()); + dummyline.PointToID = int.Parse(featureData["PointTo"].ToString()); + LineString featureline = feature.BasicGeometry as LineString; + dummyline.Coordinates = DotspLinestringToPrm(featureline); + powerlinesToPRM.Add(dummyline); + } + //create PRM_station list to pass to PRM_wind from loaded point layer + List<WindStressPRM.PowerStation> powerpointsToPRM = new List<WindStressPRM.PowerStation>(); + foreach (IFeature featurepoint in pwpointsSet.Features) + { + WindStressPRM.PowerStation dummystation = new WindStressPRM.PowerStation(); + DataRow featureData = featurepoint.DataRow; + dummystation.Identifier = featurepoint.Fid; + dummystation.Name = featureData["Name"].ToString(); + dummystation.Power = int.Parse(featureData["Power"].ToString()); + int issr = int.Parse(featureData["IsSource"].ToString()); + if (issr == 0) { - WindStressPRM.Powerline dummyline = new WindStressPRM.Powerline(); - DataRow featureData = feature.DataRow; - dummyline.Identifier = feature.Fid; - dummyline.Year = int.Parse(featureData["Year"].ToString()); - dummyline.Height = double.Parse(featureData["HeightOffs"].ToString()); - dummyline.Power = int.Parse(featureData["Power"].ToString()); - dummyline.PointFromID = int.Parse(featureData["PointFrom"].ToString()); - dummyline.PointToID = int.Parse(featureData["PointTo"].ToString()); - LineString featureline = feature.BasicGeometry as LineString; - dummyline.Coordinates = DotspLinestringToPrm(featureline); - powerlinesToPRM.Add(dummyline); + dummystation.IsSource = false; } - //create PRM_station list to pass to PRM_wind from loaded point layer - List<WindStressPRM.PowerStation> powerpointsToPRM = new List<WindStressPRM.PowerStation>(); - foreach (IFeature featurepoint in pwpointsSet.Features) + else { - WindStressPRM.PowerStation dummystation = new WindStressPRM.PowerStation(); - DataRow featureData = featurepoint.DataRow; - dummystation.Identifier = featurepoint.Fid; - dummystation.Name = featureData["Name"].ToString(); - dummystation.Power = int.Parse(featureData["Power"].ToString()); - int issr = int.Parse(featureData["IsSource"].ToString()); - if (issr == 0) + if (issr == 1) { - dummystation.IsSource = false; + dummystation.IsSource = true; } else { - if (issr == 1) - { - dummystation.IsSource = true; - } - else - { - MessageBox.Show("Some entities in Column IsSource of powerstation datatable are not strict ones or zeros"); - } + MessageBox.Show("Some entities in Column IsSource of powerstation datatable are not strict ones or zeros"); } - //casting stationtype - if (featureData["Type"].ToString().Trim().ToUpper() == "POLE") - { - dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Pole; - } - else if (featureData["Type"].ToString().Trim().ToUpper() == "TRANS") - { - dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Trans; - } - else if (featureData["Type"].ToString().Trim().ToUpper() == "ENDSTAT") - { - dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Endstat; - } - else - { - throw new System.Exception("Point in powerstation layer has unrecognised type"); } - IPoint featurepointcoords = featurepoint.BasicGeometry as IPoint; - dummystation.Coordinate = DotspPointToPRM(featurepointcoords); - powerpointsToPRM.Add(dummystation); + //casting stationtype + if (featureData["Type"].ToString().Trim().ToUpper() == "POLE") + { + dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Pole; + } + else if (featureData["Type"].ToString().Trim().ToUpper() == "TRANS") + { + dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Trans; + } + else if (featureData["Type"].ToString().Trim().ToUpper() == "ENDSTAT") + { + dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Endstat; + } + else + { + throw new System.Exception("Point in powerstation layer has unrecognised type"); + } + IPoint featurepointcoords = featurepoint.BasicGeometry as IPoint; + dummystation.Coordinate = DotspPointToPRM(featurepointcoords); + powerpointsToPRM.Add(dummystation); - } - //Create a PRM_wind class and add all the properties from above - WindStressPRM.StressPowerChecker prmwind = new WindStressPRM.StressPowerChecker(); - WindStressPRM.Input input = new WindStressPRM.Input(); - input.PowerLines = powerlinesToPRM; - input.PowerStations = powerpointsToPRM; - input.PrognosticCells = prognosticWind; - input.PrognosticCellSize = progcellsize; - input.PrognosticAffineCoefficients = prog_aff; - input.ClimateCells = climWind; - input.ClimateCellSize = climCellsize; - input.ClimateAffineCoefficients = climAffinecoeffs; - WindStressPRM.Output output = prmwind.CheckPower(input); - // new FeatureSet for resulting disabled points - IFeatureSet disabledPointSet = new FeatureSet(FeatureType.Point); + } + //Create a PRM_wind class and add all the properties from above + WindStressPRM.StressPowerChecker prmwind = new WindStressPRM.StressPowerChecker(); + WindStressPRM.Input input = new WindStressPRM.Input(); + input.PowerLines = powerlinesToPRM; + input.PowerStations = powerpointsToPRM; + input.PrognosticCells = prognosticWind; + input.PrognosticCellSize = progcellsize; + input.PrognosticAffineCoefficients = prog_aff; + input.ClimateCells = climWind; + input.ClimateCellSize = climCellsize; + input.ClimateAffineCoefficients = climAffinecoeffs; + WindStressPRM.Output output = prmwind.CheckPower(input); + // new FeatureSet for resulting disabled points + IFeatureSet disabledPointSet = new FeatureSet(FeatureType.Point); disabledPointSet.Projection = map1.Projection; DataColumn pointcolumn = new DataColumn("ID"); disabledPointSet.DataTable.Columns.Add(pointcolumn); @@ -268,7 +289,7 @@ namespace MES_Wind resultPointLayer.Symbolizer = symbol; resultPointLayer.LegendText = "Disabled TransStations"; - + //New FeatureSet for disabled powerlines IFeatureSet disabledLineSet = new FeatureSet(FeatureType.Line); disabledLineSet.Projection = map1.Projection; diff --git a/WindStressPRM/WindStressPRM.cs b/WindStressPRM/WindStressPRM.cs index cba01cbb64e18af5e39a51c28967640a150577d3..cf21967f07da0710d344c7d2eb6d81509723c1a8 100644 --- a/WindStressPRM/WindStressPRM.cs +++ b/WindStressPRM/WindStressPRM.cs @@ -13,12 +13,12 @@ namespace WindStressPRM /// Outer index /// Внешний индекс /// </summary> - public int Row; + public int Row { get; set; } /// <summary> /// Inner index /// Внутренний индекс /// </summary> - public int Col; + public int Col { get; set; } /// <summary> /// designated constructor /// </summary> @@ -27,7 +27,7 @@ namespace WindStressPRM public Index(int Row, int Col) { if (Row <= -1 || Col <= -1) { - throw new Exception("Index must be initialized with nonegative integer value"); + throw new System.ArgumentOutOfRangeException("Index must be initialized with nonegative integer value"); } this.Row = Row; this.Col = Col; @@ -42,12 +42,12 @@ namespace WindStressPRM /// easting coordinate /// Координата по широте /// </summary> - public double X; + public double X { get; private set;} /// <summary> /// northing coordinate /// Координата по долготе /// </summary> - public double Y; + public double Y { get; private set; } /// <summary> /// designated constructor /// Основной конструктор @@ -56,15 +56,12 @@ namespace WindStressPRM /// <param name="Y"></param> public Coordinate(double X, double Y) { + this.X = X; + this.Y = Y; if (!(this.CheckValue())) { throw new System.ArgumentException("Passed coordinates are not valid!"); } - else - { - this.X = X; - this.Y = Y; - } } /// <summary> /// Проверка на валидность значений @@ -72,15 +69,7 @@ namespace WindStressPRM /// <returns></returns> public bool CheckValue() { - bool checker = true; - if (X != null && Y != null) - { - checker = true; - } - else { - checker = false; - } - return checker; + return !Double.IsNaN(X) && !Double.IsInfinity(X) && !Double.IsNaN(Y) && !Double.IsInfinity(Y); } } /// <summary> @@ -93,17 +82,17 @@ namespace WindStressPRM /// U - component of wind velocity, m/s /// U - компонента скорости ветра, м/с /// </summary> - public double VelocityX; + public double VelocityX { get; private set; } /// <summary> /// V - component of wind velocity, m/s /// V - компонента скорости ветра, м/с /// </summary> - public double VelocityY; + public double VelocityY { get; private set; } /// <summary> /// Cell center coordinates /// Координаты центра ячейки /// </summary> - public Coordinate Coordinate; + public Coordinate Coordinate { get; private set; } /// <summary> /// designated constructor /// </summary> @@ -112,16 +101,13 @@ namespace WindStressPRM /// <param name="vY"> V component</param> public PrognosticCell(Coordinate coord, double vX, double vY) { + this.Coordinate = coord; + this.VelocityX = vX; + this.VelocityY = vY; if (!(this.CheckValue())) { throw new System.ArgumentException("Prognostic wind velocities are incorrect"); } - else - { - this.Coordinate = coord; - this.VelocityX = vX; - this.VelocityY = vY; - } } /// <summary> /// Проверка полей на валидность @@ -129,16 +115,17 @@ namespace WindStressPRM /// <returns></returns> public bool CheckValue() { - bool checker = false; - ///Скорость ветра на высоте 10м от поверхности на Земле не может превышать 70м/c - if (Math.Abs(VelocityX) < 70 && Math.Abs(VelocityY) < 70) - { - checker = true; + bool res1 = Double.IsNaN(VelocityX); + bool res2 = Double.IsNaN(VelocityY); + if (res1 != res2) { + return false; } - else { - checker = false; + // пустые данные + if (res1) { + return true; } - return checker; + ///Скорость ветра на высоте 10м от поверхности на Земле не может превышать 70м/c + return Math.Abs(Math.Pow(VelocityX, 2) + Math.Pow(VelocityY, 2)) <= 4900; } } /// <summary> @@ -156,17 +143,17 @@ namespace WindStressPRM /// once-in-10-years frequency wind, m/s /// скорость ветра повторяемости один раз в 10 лет, м/с /// </summary> - public double Wind10; + public double Wind10 { get; private set; } /// <summary> /// once-in-15-years frequency wind, m/s /// скорость ветра повторяемости один раз в 15 лет, м/с /// </summary> - public double Wind15; + public double Wind15 { get; private set; } /// <summary> /// Cell center coordinate pair /// Координаты центра ячейки /// </summary> - public Coordinate Coordinate; + public Coordinate Coordinate { get; private set; } /// <summary> /// designated constructor /// </summary> @@ -176,17 +163,14 @@ namespace WindStressPRM /// <param name="w15"></param> public ClimateCell(Coordinate coord, double w5, double w10, double w15) { + this.Coordinate = coord; + this.Wind5 = w5; + this.Wind10 = w10; + this.Wind15 = w15; if (!(this.CheckValue())) { throw new System.ArgumentException("Climate wind value is not correct"); } - else - { - this.Coordinate = coord; - this.Wind5 = w5; - this.Wind10 = w10; - this.Wind15 = w15; - } } /// <summary> /// Провекра валидности полей класса @@ -194,31 +178,33 @@ namespace WindStressPRM /// <returns></returns> public bool CheckValue() { - bool checker = true; - if (Math.Abs(Wind5) < 70 && Math.Abs(Wind10) < 70 && Math.Abs(Wind15) < 70) - { - checker = true; + bool c5 = Double.IsNaN(Wind5); + bool c10 = Double.IsNaN(Wind10); + bool c15 = Double.IsNaN(Wind15); + if (c5 != c10 || c5 != c15 || c5 != c10) { + return false; } - else { - checker = false; + if (c5) { + return true; } - return checker; + // ветер по модулю не должен превышать 70м/с + return Math.Abs(Wind5) < 70 && Math.Abs(Wind10) < 70 && Math.Abs(Wind15) < 70; } } /// <summary> /// Cell Size parameters /// Параметры ячейки (регулярной сетки) /// </summary> - public struct CellSize + public class CellSize { /// <summary> /// ширина ячейки (расстояние между соседними по широте центрами ячеек) /// </summary> - public double Width; + public double Width { get; set; } /// <summary> /// высота ячейки (расстояние между соседними по долготе центрами ячеек) /// </summary> - public double Height; + public double Height { get; set; } /// <summary> /// designated constructor /// </summary> @@ -239,13 +225,7 @@ namespace WindStressPRM /// <returns></returns> public bool CheckValue() { - bool checker = true; - if (Width > 0 && Height > 0) - { - checker = true; - } - else { checker = false; } - return checker; + return Width > 0 && Height > 0; } } /// <summary> @@ -263,17 +243,17 @@ namespace WindStressPRM /// year of construction /// год постройки ЛЭП /// </summary> - public int Year; + public int Year { get; set; } /// <summary> /// average height of cable span between two poles, meters /// средняя высота пролета, м /// </summary> - public double Height; + public double Height { get; set; } /// <summary> - /// power kW for switches - /// Мощность ЛЭП, кВт + /// power kV for switches + /// Напряжение ЛЭП, кВ /// </summary> - public int Power; + public int Power { get; set; } /// <summary> /// Line vertices coordinate list /// список координат вершин ЛЭП как линейного объекта @@ -283,23 +263,23 @@ namespace WindStressPRM /// assigned powerstation/pole /// идентификатор соответсвующего конца/начала линии (столб, трансформаторная подстанция, понижающая подстанция) /// </summary> - public int PointFromID; + public int PointFromID { get; set; } /// <summary> /// assigned powerstation/pole /// идентификатор соответсвующего конца/начала линии (столб, трансформаторная подстанция, понижающая подстанция) /// </summary> - public int PointToID; + public int PointToID { get; set; } /// <summary> /// broken/not broken switch /// сломана (true) или нет (false) линяя /// </summary> - public bool IsBroken; + public bool IsBroken { get; set; } /// <summary> /// power on switch /// получает (true) или нет (false) линия питание /// </summary> - public bool IsON; - private int MissingIdValue = -1; + public bool IsON { get; set; } + public Powerline() { //default constructor body @@ -338,12 +318,10 @@ namespace WindStressPRM /// <returns></returns> public bool CheckValue() { - bool checker = true; - if ( Identifier >= 0 && Math.Abs(Year - 1985) < 45 && Math.Abs(Height - 15)<15 && Power > 0 && Power < 1000 && PointFromID >=0 && PointToID >=0) - { - checker = true; - } - else { checker = false; } + bool checker = + Identifier >= 0 && Math.Abs(Year - 1985) < 45 && + Math.Abs(Height - 15) < 15 && Power > 0 && Power < 1000 && + PointFromID >= 0 && PointToID >= 0; return checker; } } @@ -357,21 +335,21 @@ namespace WindStressPRM /// unique id /// уникальный идентификатор подстанции/столба /// </summary> - public int Identifier; + public int Identifier { get; set; } /// <summary> /// Coordinates /// </summary> - public Coordinate Coordinate; + public Coordinate Coordinate { get; set; } /// <summary> /// station name field /// название подстанции /// </summary> - public string Name; + public string Name { get; set; } /// <summary> /// power, kW /// мощность, кВт /// </summary> - public int Power; + public int Power { get; set; } /// <summary> /// type of point - trans/pole/endpoint /// тип станции - трансформаторная подстанция/столб/понижающая(конечная)подстанция @@ -383,22 +361,22 @@ namespace WindStressPRM /// <summary> /// тип подстанции /// </summary> - public StationType Stationtype; + public StationType Stationtype { get; set; } /// <summary> /// is point a source? /// является ли подстаниция источником питания (в случае ТЭЦ или питания от внешних для рассматриваемой цепи ЛЭП) /// </summary> - public bool IsSource; + public bool IsSource { get; set; } /// <summary> /// power on switch /// поступает (true) или нет (false) на подстанцию питание /// </summary> - public bool IsON; + public bool IsON { get; set; } /// <summary> /// asigned powerlines list /// список оканчивающихся/начинающихся на подстанции ЛЭП /// </summary> - public List<Powerline> LineList; + public List<Powerline> LineList { get; set; } public PowerStation() { //default constructor @@ -425,14 +403,8 @@ namespace WindStressPRM } public bool CheckValue() { - bool checker = true; - if (Identifier >=0 && Power >0 && Power < 1000 ) - { - checker = true; - } - else { checker = false; } + bool checker = Identifier >=0 && Power >0 && Power < 1000; return checker; - } } @@ -502,18 +474,6 @@ namespace WindStressPRM return 500; } } - - /// <summary> - /// missing raster value for cells, if you haven't normal value use this one. - /// потерянное значение для растрового объекта; Если Вы не имеете данных - используйте это значение - /// </summary> - public double kMissingRasterValue - { - get - { - return -9999; - } - } } /// <summary> /// Output @@ -724,29 +684,19 @@ namespace WindStressPRM Coordinate subCoord2 = new Coordinate(coord1.X + constXdiff, coord1.Y + constXdiff); for (int j = 0; j < distpropI; j++) { - if (j == 0) - { - midpoint.X = (subCoord1.X + subCoord2.X) / 2; - midpoint.Y = (subCoord1.Y + subCoord2.Y) / 2; - pointlist.Add(midpoint); - } - else + if (j > 0) { - // move to next center - subCoord1.X = subCoord2.X; - subCoord1.Y = subCoord2.Y; - subCoord2.X = subCoord1.X + constXdiff; - subCoord2.Y = subCoord1.Y + constYdiff; - midpoint.X = (subCoord1.X + subCoord2.X) / 2; - midpoint.Y = (subCoord1.Y + subCoord2.Y) / 2; - pointlist.Add(midpoint); + // move to next center, at the next interval + subCoord1 = new Coordinate(subCoord2.X, subCoord2.Y); + subCoord2 = new Coordinate(subCoord1.X + constXdiff, subCoord1.Y + constYdiff); } + midpoint = new Coordinate((subCoord1.X + subCoord2.X) / 2, (subCoord1.Y + subCoord2.Y) / 2); + pointlist.Add(midpoint); } } else { - midpoint.X = (coord1.X + coord2.X) / 2; - midpoint.Y = (coord1.Y + coord2.Y) / 2; + midpoint = new Coordinate( (coord1.X + coord2.X) / 2, (coord1.Y + coord2.Y) / 2); pointlist.Add(midpoint); } FunctionType climateType; @@ -992,10 +942,11 @@ namespace WindStressPRM double valTopLeft = valueForFunction(functionType, rcTopLeft); double valTopRight = valueForFunction(functionType, rcTopRight); Coordinate origin = cellToProjection(rcBotLeft, functionType); - bool testBotLeft = valBotLeft == Input.kMissingRasterValue; - bool testBotRight = valBotRight == Input.kMissingRasterValue; - bool testTopLeft = valTopLeft == Input.kMissingRasterValue; - bool testTopRight = valTopRight == Input.kMissingRasterValue; + + bool testBotLeft = Double.IsNaN(valBotLeft); + bool testBotRight = Double.IsNaN(valBotRight); + bool testTopLeft = Double.IsNaN(valTopLeft); + bool testTopRight = Double.IsNaN(valTopRight); if (testBotLeft || testBotRight || testTopLeft || testTopRight) { // tests indicates that value at test-cell is missed.