From 86e234dce5aa574d40ce76dfa187d0b5cdd95807 Mon Sep 17 00:00:00 2001
From: Anton Kudryashov <qubabox@mail.ru>
Date: Mon, 21 Nov 2016 14:50:29 +0300
Subject: [PATCH] - fixed lists of lists with generic matrix
---
MES_Wind/frmMain.cs | 100 +++++++++++++----------------
WindStressPRM/Matrix.cs | 4 ++
WindStressPRM/WindStressPRM.cs | 50 +++++----------
WindStressPRM/WindStressPRM.csproj | 5 +-
4 files changed, 67 insertions(+), 92 deletions(-)
diff --git a/MES_Wind/frmMain.cs b/MES_Wind/frmMain.cs
index 52610a7..31ace4d 100644
--- a/MES_Wind/frmMain.cs
+++ b/MES_Wind/frmMain.cs
@@ -118,22 +118,25 @@ namespace MES_Wind
return;
}
pwlLayer = map1.GetLineLayers()[0];
- //copy line layer FeatureSet
+ // copy line layer FeatureSet
IFeatureSet pwlineSet = pwlLayer.DataSet;
- //get the powerstations layer
+ // 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
+ // 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++)
+ WindStressPRM.Matrix<WindStressPRM.PrognosticCell> prognosticMatrix = new WindStressPRM.Matrix<WindStressPRM.PrognosticCell>();
+ prognosticMatrix.Cells = new WindStressPRM.PrognosticCell[rcountPrognostic, ccountPrognostic];
+ prognosticMatrix.Size = new WindStressPRM.CellSize(uRasterLayer.DataSet.CellWidth, uRasterLayer.DataSet.CellHeight);
+ prognosticMatrix.AffineCoefficients = uRasterLayer.Bounds.AffineCoefficients;
+ // fill cells of prognostic matrix
+ for (int i = 0; i < rcountPrognostic; i++)
{
- List<WindStressPRM.PrognosticCell> progWindRow = new List<WindStressPRM.PrognosticCell>();
- for (int j =0; j< ccountPrognostic; j++ )
+ for (int j = 0; j < ccountPrognostic; j++)
{
Coordinate dummyRCoords = uRasterLayer.Bounds.CellCenter_ToProj(i,j);
WindStressPRM.Coordinate cellCoords =new WindStressPRM.Coordinate(dummyRCoords.X,dummyRCoords.Y);
@@ -146,21 +149,19 @@ namespace MES_Wind
vValue = Double.NaN;
}
WindStressPRM.PrognosticCell dummyPrognosticCell = new WindStressPRM.PrognosticCell(cellCoords, uValue, vValue);
- progWindRow.Add(dummyPrognosticCell);
+ prognosticMatrix.Cells[i, j] = dummyPrognosticCell;
}
- 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;
+ WindStressPRM.Matrix<WindStressPRM.ClimateCell> climateMatrix = new WindStressPRM.Matrix<WindStressPRM.ClimateCell>();
+ climateMatrix.Cells = new WindStressPRM.ClimateCell[rowCountClim, columnCountClim];
+ climateMatrix.Size = new WindStressPRM.CellSize(clim5RasterLayer.DataSet.CellWidth, clim5RasterLayer.DataSet.CellHeight);
+ climateMatrix.AffineCoefficients = clim5RasterLayer.Bounds.AffineCoefficients;
+ // fill cells of climate matrix
for (int i = 0; i < rowCountClim; i++)
{
- List<WindStressPRM.ClimateCell> climWindRow = new List<WindStressPRM.ClimateCell>();
for (int j = 0; j < columnCountClim; j++)
{
Coordinate dummyCellCoords = clim15RasterLayer.Bounds.CellCenter_ToProj(i,j);
@@ -182,14 +183,9 @@ namespace MES_Wind
clim15 = Double.NaN;
}
WindStressPRM.ClimateCell dummyClim = new WindStressPRM.ClimateCell(dummyClimCoords, clim5, clim10, clim15);
- climWindRow.Add(dummyClim);
+ climateMatrix.Cells[i, j] = dummyClim;
}
- 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)
@@ -231,39 +227,34 @@ namespace MES_Wind
MessageBox.Show("Some entities in Column IsSource of powerstation datatable are not strict ones or zeros");
}
}
- //casting stationtype
- if (featureData["Sttype"].ToString().Trim().ToUpper() == "POLE")
- {
- dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Pole;
- }
- else if (featureData["Sttype"].ToString().Trim().ToUpper() == "TRANS")
- {
- dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Trans;
- }
- else if (featureData["Sttype"].ToString().Trim().ToUpper() == "ENDPOINT")
- {
- dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Endstat;
- }
- else
- {
- throw new System.Exception("Point in powerstation layer has unrecognised type");
- }
+ //casting stationtype
+ if (featureData["Sttype"].ToString().Trim().ToUpper() == "POLE")
+ {
+ dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Pole;
+ }
+ else if (featureData["Sttype"].ToString().Trim().ToUpper() == "TRANS")
+ {
+ dummystation.Stationtype = WindStressPRM.PowerStation.StationType.Trans;
+ }
+ else if (featureData["Sttype"].ToString().Trim().ToUpper() == "ENDPOINT")
+ {
+ 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;
+ input.PrognosticCells = prognosticMatrix;
+ input.ClimateCells = climateMatrix;
WindStressPRM.Output output = prmwind.CheckPower(input);
// new FeatureSet for resulting disabled points
IFeatureSet disabledPointSet = new FeatureSet(FeatureType.Point);
@@ -310,17 +301,16 @@ namespace MES_Wind
disabledLineLayer.Symbolizer = lineSymbol;
disabledLineLayer.LegendText = "Disabled Lines";
+ // new FeatureSet for resulting broken powerlines
+ //IFeatureSet brklineSet = new FeatureSet(FeatureType.Line);
+ //DataTable dt = pwlineSet.DataTable;
+ //IFeatureSet brk_info = new FeatureSet(FeatureType.Line);
+ //brk_info = main_layer_function(pwlLayer, pwlineSet, u_rasterLayer, v_rasterLayer, clim15_rasterLayer, clim10_rasterLayer, clim5_rasterLayer);
- // new FeatureSet for resulting broken powerlines
- //IFeatureSet brklineSet = new FeatureSet(FeatureType.Line);
- //DataTable dt = pwlineSet.DataTable;
- //IFeatureSet brk_info = new FeatureSet(FeatureType.Line);
- //brk_info = main_layer_function(pwlLayer, pwlineSet, u_rasterLayer, v_rasterLayer, clim15_rasterLayer, clim10_rasterLayer, clim5_rasterLayer);
-
- //IMapLineLayer brk_info_layer = (MapLineLayer)map1.Layers.Add(brk_info);
- //LineSymbolizer symbol = new LineSymbolizer(Color.Red, 3);
- //brk_info_layer.Symbolizer = symbol;
- //brk_info_layer.LegendText = "Broken powerlines";
+ //IMapLineLayer brk_info_layer = (MapLineLayer)map1.Layers.Add(brk_info);
+ //LineSymbolizer symbol = new LineSymbolizer(Color.Red, 3);
+ //brk_info_layer.Symbolizer = symbol;
+ //brk_info_layer.LegendText = "Broken powerlines";
}
}
public class CheckPoint
diff --git a/WindStressPRM/Matrix.cs b/WindStressPRM/Matrix.cs
index 158561f..66a4146 100644
--- a/WindStressPRM/Matrix.cs
+++ b/WindStressPRM/Matrix.cs
@@ -9,6 +9,10 @@ namespace WindStressPRM
/// <typeparam name="T"></typeparam>
public class Matrix<T>
{
+ /// <summary>
+ /// AffineCoefficients for matrix from raster projection
+ /// </summary>
+ public double[] AffineCoefficients { get; set; }
/// <summary>
/// Size of cell. In meters
/// </summary>
diff --git a/WindStressPRM/WindStressPRM.cs b/WindStressPRM/WindStressPRM.cs
index 8c52ee5..eb5bf8a 100644
--- a/WindStressPRM/WindStressPRM.cs
+++ b/WindStressPRM/WindStressPRM.cs
@@ -394,33 +394,13 @@ namespace WindStressPRM
/// prognistic raster info
/// массив прогностического ветра
/// </summary>
- public List<List<PrognosticCell>> PrognosticCells { get; set; }
- /// <summary>
- /// prognostic raster cell info
- /// параметры ячеек регулярной сетки прогностического ветра
- /// </summary>
- public CellSize PrognosticCellSize { get; set; }
- /// <summary>
- /// affine coefficients from prognostic raster projections
- /// коэффициенты аффиного проеобразования из проекции массива прогностического ветра
- /// </summary>
- public double[] PrognosticAffineCoefficients { get; set; }
+ public Matrix<PrognosticCell> PrognosticCells { get; set; }
/// <summary>
/// climate raster array
/// массив климатических полей скорости ветра заданной повторяемости
/// </summary>
- public List<List<ClimateCell>> ClimateCells { get; set; }
- /// <summary>
- /// climate raster cell info
- /// параметры ячеек регулярной сетки климатических полей скорости ветра заданной повторяемости
- /// </summary>
- public CellSize ClimateCellSize { get; set; }
- /// <summary>
- /// affine coefficients from climate raster projection
- /// коэффициенты аффинного преобразования из проекции массива климатических полей скорости ветра заданной повторяемости
- /// </summary>
- public double[] ClimateAffineCoefficients { get; set; }
+ public Matrix<ClimateCell> ClimateCells { get; set; }
/// <summary>
/// lines list
@@ -734,13 +714,13 @@ namespace WindStressPRM
case FunctionType.FunctionVelocityX:
case FunctionType.FunctionVelocityY:
{
- return Input.PrognosticAffineCoefficients;
+ return Input.PrognosticCells.AffineCoefficients;
}
case FunctionType.FunctionClimate5:
case FunctionType.FunctionClimate10:
case FunctionType.FunctionClimate15:
{
- return Input.ClimateAffineCoefficients;
+ return Input.ClimateCells.AffineCoefficients;
}
default:
break;
@@ -790,13 +770,13 @@ namespace WindStressPRM
case FunctionType.FunctionVelocityX:
case FunctionType.FunctionVelocityY:
{
- return Input.PrognosticCells[index.Row][index.Col].Coordinate;
+ return Input.PrognosticCells.Cells[index.Row, index.Col].Coordinate;
}
case FunctionType.FunctionClimate5:
case FunctionType.FunctionClimate10:
case FunctionType.FunctionClimate15:
{
- return Input.ClimateCells[index.Row][index.Col].Coordinate;
+ return Input.ClimateCells.Cells[index.Row, index.Col].Coordinate;
}
default:
break;
@@ -811,13 +791,13 @@ namespace WindStressPRM
case FunctionType.FunctionVelocityX:
case FunctionType.FunctionVelocityY:
{
- return forRows ? Input.PrognosticCells.Count : Input.PrognosticCells[0].Count;
+ return forRows ? Input.PrognosticCells.RowsCount() : Input.PrognosticCells.ColumnCount();
}
case FunctionType.FunctionClimate5:
case FunctionType.FunctionClimate10:
case FunctionType.FunctionClimate15:
{
- return forRows ? Input.ClimateCells.Count : Input.ClimateCells[0].Count;
+ return forRows ? Input.ClimateCells.RowsCount() : Input.ClimateCells.ColumnCount();
}
default:
break;
@@ -831,23 +811,23 @@ namespace WindStressPRM
{
case FunctionType.FunctionVelocityX:
{
- return Input.PrognosticCells[index.Row][index.Col].VelocityX;
+ return Input.PrognosticCells.Cells[index.Row, index.Col].VelocityX;
}
case FunctionType.FunctionVelocityY:
{
- return Input.PrognosticCells[index.Row][index.Col].VelocityY;
+ return Input.PrognosticCells.Cells[index.Row, index.Col].VelocityY;
}
case FunctionType.FunctionClimate5:
{
- return Input.ClimateCells[index.Row][index.Col].Wind5;
+ return Input.ClimateCells.Cells[index.Row, index.Col].Wind5;
}
case FunctionType.FunctionClimate10:
{
- return Input.ClimateCells[index.Row][index.Col].Wind10;
+ return Input.ClimateCells.Cells[index.Row, index.Col].Wind10;
}
case FunctionType.FunctionClimate15:
{
- return Input.ClimateCells[index.Row][index.Col].Wind15;
+ return Input.ClimateCells.Cells[index.Row, index.Col].Wind15;
}
default:
break;
@@ -862,13 +842,13 @@ namespace WindStressPRM
case FunctionType.FunctionVelocityX:
case FunctionType.FunctionVelocityY:
{
- return Input.PrognosticCellSize;
+ return Input.PrognosticCells.Size;
}
case FunctionType.FunctionClimate5:
case FunctionType.FunctionClimate10:
case FunctionType.FunctionClimate15:
{
- return Input.ClimateCellSize;
+ return Input.ClimateCells.Size;
}
default:
break;
diff --git a/WindStressPRM/WindStressPRM.csproj b/WindStressPRM/WindStressPRM.csproj
index 91e4f65..333b5ae 100644
--- a/WindStressPRM/WindStressPRM.csproj
+++ b/WindStressPRM/WindStressPRM.csproj
@@ -8,8 +8,8 @@
<ProjectGuid>{599B5E9B-293A-4866-A50F-6BB7DC36A81C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>PRMLibrary</RootNamespace>
- <AssemblyName>PRMLibrary</AssemblyName>
+ <RootNamespace>WindStressPRM</RootNamespace>
+ <AssemblyName>WindStressPRM</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
@@ -35,6 +35,7 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Matrix.cs" />
<Compile Include="WindStressPRM.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
--
GitLab