diff --git a/MES_Wind/frmMain.cs b/MES_Wind/frmMain.cs index 5dae0a4794a3053660c237340a5fcd3e394059a6..1d81b077115a780d5bff7eb5c5692e95f6f90b01 100644 --- a/MES_Wind/frmMain.cs +++ b/MES_Wind/frmMain.cs @@ -180,14 +180,14 @@ namespace MES_Wind { 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()); + 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.coords = DotspLinestringToPrm(featureline); + dummyline.Coordinates = DotspLinestringToPrm(featureline); powerlinesToPRM.Add(dummyline); } //create PRM_station list to pass to PRM_wind from loaded point layer @@ -196,19 +196,19 @@ namespace MES_Wind { 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()); + 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) { - dummystation.issource = false; + dummystation.IsSource = false; } else { if (issr == 1) { - dummystation.issource = true; + dummystation.IsSource = true; } else { @@ -218,45 +218,45 @@ namespace MES_Wind //casting stationtype if (featureData["Type"].ToString().Trim().ToUpper() == "POLE") { - dummystation.type = WindStressPRM.PowerStation.stationtype.pole; + dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Pole; } else if (featureData["Type"].ToString().Trim().ToUpper() == "TRANS") { - dummystation.type = WindStressPRM.PowerStation.stationtype.trans; + dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Trans; } else if (featureData["Type"].ToString().Trim().ToUpper() == "ENDSTAT") { - dummystation.type = WindStressPRM.PowerStation.stationtype.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.coords = DotspPointToPRM(featurepointcoords); + 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; + 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); - foreach (WindStressPRM.PowerStation disabledStation in output.disabledStations) + foreach (WindStressPRM.PowerStation disabledStation in output.DisabledStations) { - Coordinate coords = new Coordinate(disabledStation.coords.X, disabledStation.coords.Y); + Coordinate coords = new Coordinate(disabledStation.Coordinate.X, disabledStation.Coordinate.Y); DotSpatial.Topology.Point disabledPoint = new DotSpatial.Topology.Point(coords); Feature disabledPointFeature = new Feature(disabledPoint); //disabledPointFeature.DataRow["ID"] = disabledStation.identifier; @@ -275,17 +275,17 @@ namespace MES_Wind DataColumn lineIDcolumn = new DataColumn("ID"); disabledLineSet.DataTable.Columns.Add(lineIDcolumn); int lineID = 0; - foreach (WindStressPRM.Powerline disabledLine in output.disabledLines) + foreach (WindStressPRM.Powerline disabledLine in output.DisabledLines) { List<Coordinate> lineArray = new List<Coordinate>(); - foreach (WindStressPRM.Coordinate prmcoordinate in disabledLine.coords) + foreach (WindStressPRM.Coordinate prmcoordinate in disabledLine.Coordinates) { Coordinate lineVerticeCoords = new Coordinate(prmcoordinate.X, prmcoordinate.Y); lineArray.Add(lineVerticeCoords); } LineString lineGeometry = new LineString(lineArray); IFeature lineFeature = disabledLineSet.AddFeature(lineGeometry); - lineID = disabledLine.identifier; + lineID = disabledLine.Identifier; lineFeature.DataRow["ID"] = lineID; } //add resulting layer to the map diff --git a/WindStressPRM/WindStressPRM.cs b/WindStressPRM/WindStressPRM.cs index 059d85d8aedccac270dcdc4f7388e5a75b8fedff..4d930cc610babde68cd1842021b930ce41aaacd2 100644 --- a/WindStressPRM/WindStressPRM.cs +++ b/WindStressPRM/WindStressPRM.cs @@ -57,7 +57,7 @@ namespace WindStressPRM public Coordinate(double X, double Y) { if (!(this.CheckValue())) - { + { throw new System.ArgumentException("Passed coordinates are not valid!"); } else @@ -73,10 +73,13 @@ namespace WindStressPRM public bool CheckValue() { bool checker = true; - if (X != null) { checker = true; } - else { checker = false; } - if (Y != null) { checker = true; } - else { checker = false; } + if (X != null && Y != null) + { + checker = true; + } + else { + checker = false; + } return checker; } } @@ -90,17 +93,17 @@ namespace WindStressPRM /// U - component of wind velocity, m/s /// U - компонента скорости ветра, м/с /// </summary> - public double velocityX; + public double VelocityX; /// <summary> /// V - component of wind velocity, m/s /// V - компонента скорости ветра, м/с /// </summary> - public double velocityY; + public double VelocityY; /// <summary> /// Cell center coordinates /// Координаты центра ячейки /// </summary> - public Coordinate coords; + public Coordinate Coordinate; /// <summary> /// designated constructor /// </summary> @@ -115,9 +118,9 @@ namespace WindStressPRM } else { - this.coords = coord; - this.velocityX = vX; - this.velocityY = vY; + this.Coordinate = coord; + this.VelocityX = vX; + this.VelocityY = vY; } } /// <summary> @@ -128,10 +131,13 @@ namespace WindStressPRM { bool checker = false; ///Скорость ветра на высоте 10м от поверхности на Земле не может превышать 70м/c - if (Math.Abs(velocityX) < 70) { checker = true; } - else { checker = false; } - if (Math.Abs(velocityY) < 70) { checker = true; } - else { checker = false; } + if (Math.Abs(VelocityX) < 70 && Math.Abs(VelocityY) < 70) + { + checker = true; + } + else { + checker = false; + } return checker; } } @@ -145,22 +151,22 @@ namespace WindStressPRM /// once-in-5-years frequency wind, m/s /// скорость ветра повторяемости один раз в 5 лет, м/с /// </summary> - public double wind5; + public double Wind5; /// <summary> /// once-in-10-years frequency wind, m/s /// скорость ветра повторяемости один раз в 10 лет, м/с /// </summary> - public double wind10; + public double Wind10; /// <summary> /// once-in-15-years frequency wind, m/s /// скорость ветра повторяемости один раз в 15 лет, м/с /// </summary> - public double wind15; + public double Wind15; /// <summary> /// Cell center coordinate pair /// Координаты центра ячейки /// </summary> - public Coordinate coords; + public Coordinate Coordinate; /// <summary> /// designated constructor /// </summary> @@ -176,10 +182,10 @@ namespace WindStressPRM } else { - this.coords = coord; - this.wind5 = w5; - this.wind10 = w10; - this.wind15 = w15; + this.Coordinate = coord; + this.Wind5 = w5; + this.Wind10 = w10; + this.Wind15 = w15; } } /// <summary> @@ -189,8 +195,13 @@ namespace WindStressPRM public bool CheckValue() { bool checker = true; - if (Math.Abs(wind5) < 70 && Math.Abs(wind10) < 70 && Math.Abs(wind15) < 70) { checker = true; } - else { checker = false; } + if (Math.Abs(Wind5) < 70 && Math.Abs(Wind10) < 70 && Math.Abs(Wind15) < 70) + { + checker = true; + } + else { + checker = false; + } return checker; } } @@ -203,11 +214,11 @@ namespace WindStressPRM /// <summary> /// ширина ячейки (расстояние между соседними по широте центрами ячеек) /// </summary> - public double width; + public double Width; /// <summary> /// высота ячейки (расстояние между соседними по долготе центрами ячеек) /// </summary> - public double height; + public double Height; /// <summary> /// designated constructor /// </summary> @@ -215,8 +226,8 @@ namespace WindStressPRM /// <param name="hgh">Cell Height</param> public CellSize(double wdh, double hgh) { - this.width = wdh; - this.height = hgh; + this.Width = wdh; + this.Height = hgh; if (!(this.CheckValue())) { throw new System.ArgumentException("Cell width or height values are incorrect!"); @@ -229,7 +240,10 @@ namespace WindStressPRM public bool CheckValue() { bool checker = true; - if (width > 0 && height > 0) { checker = true; } + if (Width > 0 && Height > 0) + { + checker = true; + } else { checker = false; } return checker; } @@ -244,47 +258,47 @@ namespace WindStressPRM /// 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> Coordinates { 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 /// сломана (true) или нет (false) линяя /// </summary> - public bool isbroken; + public bool IsBroken; /// <summary> /// power on switch /// получает (true) или нет (false) линия питание /// </summary> - public bool ison; + public bool IsON; private int MissingIdValue = -1; public Powerline() { @@ -304,17 +318,19 @@ namespace WindStressPRM /// <param name="fromID"></param> public Powerline(List<Coordinate> coordinates, int id, int year, double height, int power, int toID, int fromID) { - this.coords = coordinates; - this.identifier = id; - this.year = year; - this.height = height; - this.power = power; - this.isbroken = false; - this.ison = false; - this.pointFromID = fromID; - this.pointToID = toID; + this.Coordinates = coordinates; + this.Identifier = id; + this.Year = year; + this.Height = height; + this.Power = power; + this.IsBroken = false; + this.IsON = false; + this.PointFromID = fromID; + this.PointToID = toID; if (!(this.CheckValue())) - { throw new System.ArgumentException("Powerline object wasn't initialized correctly"); } + { + throw new System.ArgumentException("Powerline object wasn't initialized correctly"); + } } /// <summary> /// проверка валидности полей @@ -323,8 +339,10 @@ namespace WindStressPRM 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; } + 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; } return checker; } @@ -339,45 +357,48 @@ namespace WindStressPRM /// unique id /// уникальный идентификатор подстанции/столба /// </summary> - public int identifier; + public int Identifier; /// <summary> /// Coordinates /// </summary> - public Coordinate coords; + public Coordinate Coordinate; /// <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 enum stationtype {pole, trans, endstat}; + public enum StationType + { + Pole, Trans, Endstat + }; /// <summary> /// тип подстанции /// </summary> - public stationtype type; + public StationType Stationtype; /// <summary> /// is point a source? /// является ли подстаниция источником питания (в случае ТЭЦ или питания от внешних для рассматриваемой цепи ЛЭП) /// </summary> - public bool issource; + public bool IsSource; /// <summary> /// power on switch /// поступает (true) или нет (false) на подстанцию питание /// </summary> - public bool ison; + public bool IsON; /// <summary> /// asigned powerlines list /// список оканчивающихся/начинающихся на подстанции ЛЭП /// </summary> - public List<Powerline> linelist; + public List<Powerline> LineList; public PowerStation() { //default constructor @@ -392,21 +413,23 @@ namespace WindStressPRM /// <param name="sttype"></param> /// <param name="issource"></param> /// <param name="ison"></param> - public PowerStation(Coordinate crds, int id, string stname, int stpower, stationtype sttype, bool issource) + public PowerStation(Coordinate crds, int id, string stname, int stpower, StationType sttype, bool issource) { - this.coords = crds; - this.identifier = id; - this.name = stname; - this.power = stpower; - this.type = sttype; - this.issource = issource; - this.ison = false; + this.Coordinate = crds; + this.Identifier = id; + this.Name = stname; + this.Power = stpower; + this.Stationtype = sttype; + this.IsSource = issource; + this.IsON = false; } public bool CheckValue() { bool checker = true; - if (identifier >=0 && power >0 && power < 1000 ) - { checker = true; } + if (Identifier >=0 && Power >0 && Power < 1000 ) + { + checker = true; + } else { checker = false; } return checker; @@ -430,55 +453,67 @@ namespace WindStressPRM /// prognistic raster info /// массив прогностического ветра /// </summary> - public List<List<PrognosticCell>> prognosticCells {get; set;} + public List<List<PrognosticCell>> PrognosticCells { get; set; } /// <summary> /// prognostic raster cell info /// параметры ячеек регулярной сетки прогностического ветра /// </summary> - public CellSize prognosticCellSize { get; set; } + public CellSize PrognosticCellSize { get; set; } /// <summary> /// affine coefficients from prognostic raster projections /// коэффициенты аффиного проеобразования из проекции массива прогностического ветра /// </summary> - public double[] prognosticAffineCoefficients { get; set; } + public double[] PrognosticAffineCoefficients { get; set; } /// <summary> /// climate raster array /// массив климатических полей скорости ветра заданной повторяемости /// </summary> - public List<List<ClimateCell>> climateCells { get; set; } + public List<List<ClimateCell>> ClimateCells { get; set; } /// <summary> /// climate raster cell info /// параметры ячеек регулярной сетки климатических полей скорости ветра заданной повторяемости /// </summary> - public CellSize climateCellSize { get; set; } + public CellSize ClimateCellSize { get; set; } /// <summary> /// affine coefficients from climate raster projection /// коэффициенты аффинного преобразования из проекции массива климатических полей скорости ветра заданной повторяемости /// </summary> - public double[] climateAffineCoefficients { get; set; } + public double[] ClimateAffineCoefficients { get; set; } /// <summary> /// lines list /// список ЛЭП /// </summary> - public List<Powerline> powerLines { get; set; } + public List<Powerline> PowerLines { get; set; } /// <summary> /// stations/poles list /// список точечных объектов - трансформаторных подстанций/столбов/понижающих(конечных) подстанций /// </summary> - public List<PowerStation> powerStations { get; set; } + public List<PowerStation> PowerStations { get; set; } /// <summary> /// maximum distance for line segment, meters /// максимальное расстояние между точками ЛЭП, для которых проверяется сломаются/несломаются под действием ветра /// </summary> - public double dist_threshold + public double DistThreshold { get { 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 @@ -489,12 +524,12 @@ namespace WindStressPRM /// stations list without power /// Список подстанций на которые не поступит питание в результате предсказанных поломок ЛЭП в сети /// </summary> - public List<PowerStation> disabledStations { get; set; } + public List<PowerStation> DisabledStations { get; set; } /// <summary> /// broken lines list /// Список прогнозируемых сломанных ЛЭП в результате ветрового воздействия /// </summary> - public List<Powerline> disabledLines { get; set; } + public List<Powerline> DisabledLines { get; set; } } /// <summary> /// main calculations class @@ -504,7 +539,7 @@ namespace WindStressPRM /// <summary> /// Input Data /// </summary> - private Input input; + private Input Input; /// <summary> /// Main function for power graph algorithm @@ -512,36 +547,36 @@ namespace WindStressPRM /// </summary> public Output CheckPower(Input input) { - this.input = input; + this.Input = input; //Calculate which lines are broken List<WindStressPRM.Powerline> prmBrokenLines = brokenPowerLinesAfterCheck(); //get the graph PreparingPowerItems(); //start from source points - foreach (PowerStation pwstation in input.powerStations) + foreach (PowerStation pwstation in input.PowerStations) { - if (pwstation.issource) + if (pwstation.IsSource) { CheckPowerPointsForStation(pwstation); } } //fill output Output output = new Output(); - output.disabledStations = new List<PowerStation>(); - output.disabledLines = new List<Powerline>(); - foreach (Powerline line in input.powerLines) + output.DisabledStations = new List<PowerStation>(); + output.DisabledLines = new List<Powerline>(); + foreach (Powerline line in input.PowerLines) { - if (line.isbroken) + if (line.IsBroken) { - output.disabledLines.Add(line); + output.DisabledLines.Add(line); } } - foreach (PowerStation powerStation in input.powerStations) + foreach (PowerStation powerStation in input.PowerStations) { //stations of type pole can be disabled if the line is broken - if (!powerStation.ison && !(powerStation.type == PowerStation.stationtype.pole)) + if (!powerStation.IsON && !(powerStation.Stationtype == PowerStation.StationType.Pole)) { - output.disabledStations.Add(powerStation); + output.DisabledStations.Add(powerStation); } } return output; @@ -552,39 +587,39 @@ namespace WindStressPRM /// <param name="sourcepoint"> powered station to search next powered station from</param> private void CheckPowerPointsForStation(PowerStation sourcepoint) { - if (!sourcepoint.ison) + if (!sourcepoint.IsON) { throw new Exception("CheckPowerPointsForStation is called from disabled sourcepoint"); } // if the point is not a pole - i.e. we know // it can redistribute power within connected lines // we turn it ON if any of the connected lines are powered - foreach (Powerline line in sourcepoint.linelist) + foreach (Powerline line in sourcepoint.LineList) { - if (!line.isbroken && !line.ison) + if (!line.IsBroken && !line.IsON) { - line.ison = true; - foreach (PowerStation powerStation in input.powerStations) + line.IsON = true; + foreach (PowerStation powerStation in Input.PowerStations) { - if (powerStation.identifier != sourcepoint.identifier && (powerStation.identifier == line.pointFromID || powerStation.identifier == line.pointToID)) + if (powerStation.Identifier != sourcepoint.Identifier && (powerStation.Identifier == line.PointFromID || powerStation.Identifier == line.PointToID)) { - if (!(sourcepoint.type == PowerStation.stationtype.pole)) { - powerStation.ison = true; + if (!(sourcepoint.Stationtype == PowerStation.StationType.Pole)) { + powerStation.IsON = true; CheckPowerPointsForStation(powerStation); } else { // if line is a pole we have to check if it's actually able to // get electricity to other points i.e. no connected lines are broken bool powerLineCheck = false; - foreach (Powerline powerline in powerStation.linelist) + foreach (Powerline powerline in powerStation.LineList) { - if (powerline.isbroken) { + if (powerline.IsBroken) { powerLineCheck = true; } } if (!powerLineCheck) { - powerStation.ison = true; + powerStation.IsON = true; CheckPowerPointsForStation(powerStation); } } @@ -602,26 +637,26 @@ namespace WindStressPRM { //First we make sure that all the sources are ON //and all non sources are OFF - foreach (PowerStation powerStation in input.powerStations) + foreach (PowerStation powerStation in Input.PowerStations) { - if (powerStation.issource == true) { - powerStation.ison = true; + if (powerStation.IsSource == true) { + powerStation.IsON = true; } else { - powerStation.ison = false; + powerStation.IsON = false; } // for each power station we create a list of powerlines it is attached to List<Powerline> lines = new List<Powerline>(); - foreach (Powerline line in input.powerLines) + foreach (Powerline line in Input.PowerLines) { //we also switch OFF all lines - line.ison = false; - if (line.pointFromID == powerStation.identifier || line.pointToID == powerStation.identifier) { + line.IsON = false; + if (line.PointFromID == powerStation.Identifier || line.PointToID == powerStation.Identifier) { lines.Add(line); } } - powerStation.linelist = lines; + powerStation.LineList = lines; } } /// <summary> @@ -632,10 +667,10 @@ namespace WindStressPRM { List<Powerline> brokenLines = new List<Powerline>(); // actually there are curves in powerLines - foreach (Powerline powerCurve in input.powerLines) + foreach (Powerline powerCurve in Input.PowerLines) { // get coordinates list - List<Coordinate> points = powerCurve.coords; + List<Coordinate> points = powerCurve.Coordinates; List<bool> checkList = new List<bool>(); // cycle throw all points in line @@ -645,17 +680,17 @@ namespace WindStressPRM double y1 = points[i - 1].Y; double x2 = points[i].X; double y2 = points[i].Y; - bool result = linearLineIsBroken(points[i - 1], points[i], powerCurve.height, powerCurve.power); + bool result = linearLineIsBroken(points[i - 1], points[i], powerCurve.Height, powerCurve.Power); checkList.Add(result); } foreach (bool chkpnt in checkList) { if (chkpnt == true) { - powerCurve.isbroken = true; + powerCurve.IsBroken = true; } } - if (powerCurve.isbroken) + if (powerCurve.IsBroken) { brokenLines.Add(powerCurve); } @@ -677,7 +712,7 @@ namespace WindStressPRM 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 distpropD = distance / input.dist_threshold; + double distpropD = distance / Input.DistThreshold; List<Coordinate> pointlist = new List<Coordinate>(); Coordinate midpoint = new Coordinate(0, 0); int distpropI = Convert.ToInt32(distpropD); @@ -778,13 +813,13 @@ namespace WindStressPRM case FunctionType.FunctionVelocityX: case FunctionType.FunctionVelocityY: { - return input.prognosticAffineCoefficients; + return Input.PrognosticAffineCoefficients; } case FunctionType.FunctionClimate5: case FunctionType.FunctionClimate10: case FunctionType.FunctionClimate15: { - return input.climateAffineCoefficients; + return Input.ClimateAffineCoefficients; } default: break; @@ -834,13 +869,13 @@ namespace WindStressPRM case FunctionType.FunctionVelocityX: case FunctionType.FunctionVelocityY: { - return input.prognosticCells[index.Row][index.Col].coords; + return Input.PrognosticCells[index.Row][index.Col].Coordinate; } case FunctionType.FunctionClimate5: case FunctionType.FunctionClimate10: case FunctionType.FunctionClimate15: { - return input.climateCells[index.Row][index.Col].coords; + return Input.ClimateCells[index.Row][index.Col].Coordinate; } default: break; @@ -855,13 +890,13 @@ namespace WindStressPRM case FunctionType.FunctionVelocityX: case FunctionType.FunctionVelocityY: { - return forRows ? input.prognosticCells.Count : input.prognosticCells[0].Count; + return forRows ? Input.PrognosticCells.Count : Input.PrognosticCells[0].Count; } case FunctionType.FunctionClimate5: case FunctionType.FunctionClimate10: case FunctionType.FunctionClimate15: { - return forRows ? input.climateCells.Count : input.climateCells[0].Count; + return forRows ? Input.ClimateCells.Count : Input.ClimateCells[0].Count; } default: break; @@ -875,23 +910,23 @@ namespace WindStressPRM { case FunctionType.FunctionVelocityX: { - return input.prognosticCells[index.Row][index.Col].velocityX; + return Input.PrognosticCells[index.Row][index.Col].VelocityX; } case FunctionType.FunctionVelocityY: { - return input.prognosticCells[index.Row][index.Col].velocityY; + return Input.PrognosticCells[index.Row][index.Col].VelocityY; } case FunctionType.FunctionClimate5: { - return input.climateCells[index.Row][index.Col].wind5; + return Input.ClimateCells[index.Row][index.Col].Wind5; } case FunctionType.FunctionClimate10: { - return input.climateCells[index.Row][index.Col].wind10; + return Input.ClimateCells[index.Row][index.Col].Wind10; } case FunctionType.FunctionClimate15: { - return input.climateCells[index.Row][index.Col].wind15; + return Input.ClimateCells[index.Row][index.Col].Wind15; } default: break; @@ -906,13 +941,13 @@ namespace WindStressPRM case FunctionType.FunctionVelocityX: case FunctionType.FunctionVelocityY: { - return input.prognosticCellSize; + return Input.PrognosticCellSize; } case FunctionType.FunctionClimate5: case FunctionType.FunctionClimate10: case FunctionType.FunctionClimate15: { - return input.climateCellSize; + return Input.ClimateCellSize; } default: break; @@ -957,10 +992,63 @@ namespace WindStressPRM double valTopLeft = valueForFunction(functionType, rcTopLeft); double valTopRight = valueForFunction(functionType, rcTopRight); Coordinate origin = cellToProjection(rcBotLeft, functionType); - //PRM_coordinate last = cellToProjection(rcTopRight, functionType);//test only + bool testBotLeft = valBotLeft == Input.kMissingRasterValue; + bool testBotRight = valBotRight == Input.kMissingRasterValue; + bool testTopLeft = valTopLeft == Input.kMissingRasterValue; + bool testTopRight = valTopRight == Input.kMissingRasterValue; + if (testBotLeft || testBotRight || testTopLeft || testTopRight) + { + // tests indicates that value at test-cell is missed. + if (testTopRight && testTopLeft && testBotLeft && testBotRight) + { + throw new Exception("Current value in such a bad place, you need to fill these place with raster values"); + } + int count = 0; + if (testBotLeft) + { + valBotLeft = 0; + count++; + } + if (testBotRight) + { + valBotRight = 0; + count++; + } + if (testTopLeft) + { + valTopLeft = 0; + count++; + } + if (testTopRight) + { + valTopRight = 0; + count++; + } + //of course there is count not 0; + if (count == 0) { + throw new Exception("Interpolation Logic Error"); + } + double average = (valTopLeft + valTopRight + valBotLeft + valBotRight)/count; + if (testBotLeft) + { + valBotLeft = average; + } + if (testBotRight) + { + valBotRight = average; + } + if (testTopLeft) + { + valTopLeft = average; + } + if (testTopRight) + { + valTopRight = average; + } + } // sizes for cell - double hx = cellSizeForFunction(functionType).width; - double hy = cellSizeForFunction(functionType).height; + double hx = cellSizeForFunction(functionType).Width; + double hy = cellSizeForFunction(functionType).Height; // coefficients double px = (coords.X - origin.X) / hx; double py = (coords.Y - origin.Y) / hy;