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

- start classes refactoring

parent 7693acfc
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -111,6 +111,7 @@
<Compile Include="frmMain.Designer.cs">
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="PRM_wind.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="frmGraph.resx">
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MES_Wind
{
public class PRM_coordinate
{
public double X;
public double Y;
public PRM_coordinate(double X, double Y)
{
this.X = X;
this.Y = Y;
}
public PRM_coordinate() : this(0, 0) { }
}
public class PRM_raster_cell_prognostic
{
public double velocityX;
public double velocityY;
public PRM_coordinate coords;
}
public class PRM_raster_cell_climate
{
public double wind5;
public double wind10;
public double wind15;
public PRM_coordinate coords;
}
public struct PRM_cell_size
{
public double width;
public double height;
}
class PRM_Line
{
public int identifier { get; private set; }
public int year;
public double height;
public int power;
public List<PRM_coordinate> coords { get; private set; }
public bool isbroken;
}
public class PRM_Station
{
int identifier;
//TODO
}
class PRM_wind
{
//prognistic raster info
List<List<PRM_raster_cell_prognostic>> prognostic_cells;
PRM_cell_size prognostic_cellsize;
//climate raster info
List<List<PRM_raster_cell_climate>> climate_cells;
PRM_cell_size climate_cellsize;
//lines collection
List<PRM_Line> powerlines;
#region "control parameters"
public double dist_threshold;
#endregion
List<PRM_Line> brokenPowerLinesAfterCheck()
{
foreach (PRM_Line curve in powerlines)
{
// get coordinates list
List<PRM_coordinate> points = curve.coords;
List<bool> checkList = new List<bool>();
// cycle throw all points in line
for (int i = 1; i < points.Count; i++)
{
List<CheckPoint> segmentCheckList = new List<CheckPoint>();
double x1 = points[i - 1].X;
double y1 = points[i - 1].Y;
double x2 = points[i].X;
double y2 = points[i].Y;
bool result = linearLineIsBroken(points[i - 1], points[i], curve.height, curve.power, curve.power > 5 && curve.power < 330);
checkList.Add(result);
}
foreach (bool chkpnt in checkList)
{
if (chkpnt == true)
{
curve.isbroken = true;
}
}
}
if (powerlines.Count == 0)
{
throw new Exception("shit you trying to feed it is not a simple line");
//return null;
}
return null;
}
bool linearLineIsBroken(PRM_coordinate coord1, PRM_coordinate coord2, double heightLine, int powerLine, bool useClimate10)
{
double distance = Math.Sqrt((coord2.X - coord1.X) * (coord2.X - coord1.X) + (coord2.Y - coord1.Y) * (coord2.Y - coord1.Y));
double distpropD = distance / dist_threshold;
int distpropI = Convert.ToInt32(distpropD);
if (distpropI > 1)
{
double constXdiff = (coord2.X - coord1.X) / distpropI;
double constYdiff = (coord2.Y - coord1.Y) / distpropI;
PRM_coordinate subCoord1 = new PRM_coordinate(coord1.X, coord1.Y);
PRM_coordinate subCoord2 = new PRM_coordinate(coord1.X + constXdiff, coord1.Y + constXdiff);
for (int j = 0; j < distpropI; j++)
{
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;
}
bool result = linearLineIsBroken(subCoord1, subCoord2, heightLine, powerLine, useClimate10);
if (result)
{
return result;
}
}
}
else
{
double uwind = 0; // interpol(coords, Uwind_raster);
double vwind = 0; // interpol(coords, Vwind_raster);
double climwind = 0; // interpol(coords, clim_layer);
double umod = Math.Sqrt(uwind * uwind + vwind * vwind); ;
double angleline = Math.Atan2((coord2.Y - coord1.Y), (coord2.X - coord1.X));
double anglewind = Math.Atan2(vwind, uwind) - angleline;
double sinwind = Math.Sin(anglewind);
double C_height = 1.0;
if (umod < 20)
{ //wind is too low
return false;
}
else
{ // calculate prognostic and threshold windstress
double p1 = -0.00078501;
double p2 = 0.13431;
double p3 = -2.11112;
double p4 = 19.548;
double qpr = p1 * umod * umod * umod + p2 * umod * umod + p3 * umod + p4;
double qcl = p1 * climwind * climwind * climwind + p2 * climwind * climwind + p3 * climwind + p4;
double Ppr = qpr * C_height * sinwind * sinwind;
double Pcl = qcl * C_height * 1.0;
if (Ppr >= Pcl)
{
// here line is broken
return true;
}
}
}
return false;
}
}
}
No preview for this file type
......@@ -183,52 +183,8 @@ namespace MES_Wind
fullCheckList.AddRange(lineCheckList);
}
else
{//case if powerline is multiline
MultiLineString multiline = feature.BasicGeometry as MultiLineString;
if (multiline != null)
{
foreach (IGeometry line in multiline.Geometries)
{
IList<Coordinate> points = line.Coordinates;
for (int i = 1; i < points.Count; i++)
{
List<CheckPoint> segmentCheckList = new List<CheckPoint>();
double x1 = points[i - 1].X;
double y1 = points[i - 1].Y;
double x2 = points[i].X;
double y2 = points[i].Y;
if (power > 5 && power < 330)
{
segmentCheckList = CalcBrkPoint(x1, y1, x2, y2, distThreshold, u_raster, v_raster, clim10_raster, height);
}
else
{
segmentCheckList = CalcBrkPoint(x1, y1, x2, y2, distThreshold, u_raster, v_raster, clim5_raster, height);
}
bool linechek = false;
foreach (CheckPoint chkpnt in lineCheckList)
{
if (chkpnt.Ifbroken == true)
{ linechek = true; }
}
if (linechek == true)
{
IFeature lineFeature = result_layer.AddFeature(linestr);
}
lineCheckList.AddRange(segmentCheckList);
}
fullCheckList.AddRange(lineCheckList);
}
MessageBox.Show("Works");
}
else {
MessageBox.Show("shit you trying to feed it is not a simple line");
}
}
......@@ -382,6 +338,7 @@ namespace MES_Wind
IMapRasterLayer v_rasterLayer = default(IMapRasterLayer);
IMapRasterLayer clim5_rasterLayer = default(IMapRasterLayer);
IMapRasterLayer clim10_rasterLayer = default(IMapRasterLayer);
if (map1.GetRasterLayers().Count() == 1)
{
MessageBox.Show("Please add a raster layer");
......@@ -427,17 +384,6 @@ namespace MES_Wind
}
}
public class PathPoint
{
public double X1;
public double Y1;
public double X2;
public double Y2;
public double Distance;
public double Uwind;
public double Vwind;
public int Year;
}
public class CheckPoint
{
public double X;
......
No preview for this file type
......@@ -206,3 +206,5 @@ C:\Users\Geophyslab-laptop\Documents\MES_Wind2\MES_Wind\obj\Debug\MES_Wind.Prope
C:\Users\Geophyslab-laptop\Documents\MES_Wind2\MES_Wind\obj\Debug\MES_Wind.csproj.GenerateResource.Cache
C:\Users\Geophyslab-laptop\Documents\MES_Wind2\MES_Wind\bin\Debug\MES_Wind.exe
C:\Users\Geophyslab-laptop\Documents\MES_Wind2\MES_Wind\bin\Debug\MES_Wind.pdb
C:\gitlab_wind\MES_Wind\obj\Debug\MES_Wind.exe
C:\gitlab_wind\MES_Wind\obj\Debug\MES_Wind.pdb
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment