Hello, i need to speed up a loop trough alot of shapes. Im looping trough them to put all points into a table. This is for calculating the actual position on a road (in meters from the begining of the road).
There can be more than one road on top of each other so i do the loop in a prarallel.foreach.
On one road there is about 5000-10000 loops. This takes about total time of 40sec when there is 3 roads.
foreach (DataRow row in query)
{
Shape = int.Parse(row[14].ToString());
if (riktning == "Mot")
{
if (row.ItemArray[5].ToString() != "Syskonbak")
{
if (row.ItemArray[4].ToString() == "Mot")
{
for (var i_shape = 0; i_shape <= shapeFile.Shape[Shape].numPoints - 2; i_shape++)
{
count += 1;
MapWinGIS.Point a = new MapWinGIS.Point();
MapWinGIS.Point b = new MapWinGIS.Point();
a = shapeFile.QuickPoint(Shape, i_shape);
b = shapeFile.QuickPoint(Shape, i_shape + 1);
shapeLength = Math.Sqrt((Math.Pow(Math.Abs(b.x - a.x), 2)) + (Math.Pow(Math.Abs(b.y - a.y), 2)));
start_a = stop_a;
stop_a = start_a + shapeLength;
dt.Rows.Add(Shape, a.x, a.y, b.x, b.y, shapeLength, start_a, stop_a);
}
}
else
{
for (var i_shape = shapeFile.Shape[Shape].numPoints - 1; i_shape >= 1; i_shape += -1)
{
count += 1;
MapWinGIS.Point a = new MapWinGIS.Point();
MapWinGIS.Point b = new MapWinGIS.Point();
a = shapeFile.QuickPoint(Shape, i_shape);
b = shapeFile.QuickPoint(Shape, i_shape - 1);
shapeLength = Math.Sqrt((Math.Pow(Math.Abs(b.x - a.x), 2)) + (Math.Pow(Math.Abs(b.y - a.y), 2)));
start_a = stop_a;
stop_a = start_a + shapeLength;
dt.Rows.Add(Shape, a.x, a.y, b.x, b.y, shapeLength, start_a, stop_a);
}
}
}
else
{
for (var i_shape = 0; i_shape <= shapeFile.Shape[Shape].numPoints - 2; i_shape++)
{
count += 1;
MapWinGIS.Point a = new MapWinGIS.Point();
MapWinGIS.Point b = new MapWinGIS.Point();
a = shapeFile.QuickPoint(Shape, i_shape);
b = shapeFile.QuickPoint(Shape, i_shape + 1);
shapeLength = Math.Sqrt((Math.Pow(Math.Abs(b.x - a.x), 2)) + (Math.Pow(Math.Abs(b.y - a.y), 2)));
start_a = stop_a;
stop_a = start_a + shapeLength;
dt.Rows.Add(Shape, a.x, a.y, b.x, b.y, shapeLength, start_a, stop_a);
}
}
}
else
{
if (row.ItemArray[4].ToString() == "Mot")
{
for (var i_shape = shapeFile.Shape[Shape].numPoints - 1; i_shape >= 1; i_shape += -1)
{
count += 1;
MapWinGIS.Point a = new MapWinGIS.Point();
MapWinGIS.Point b = new MapWinGIS.Point();
a = shapeFile.QuickPoint(Shape, i_shape);
b = shapeFile.QuickPoint(Shape, i_shape - 1);
shapeLength = Math.Sqrt((Math.Pow(Math.Abs(b.x - a.x), 2)) + (Math.Pow(Math.Abs(b.y - a.y), 2)));
start_a = stop_a;
stop_a = start_a + shapeLength;
dt.Rows.Add(Shape, a.x, a.y, b.x, b.y, shapeLength, start_a, stop_a);
}
}
else
{
for (var i_shape = 0; i_shape <= shapeFile.Shape[Shape].numPoints - 2; i_shape++)
{
count += 1;
MapWinGIS.Point a = new MapWinGIS.Point();
MapWinGIS.Point b = new MapWinGIS.Point();
a = shapeFile.QuickPoint(Shape, i_shape);
b = shapeFile.QuickPoint(Shape, i_shape + 1);
shapeLength = Math.Sqrt((Math.Pow(Math.Abs(b.x - a.x), 2)) + (Math.Pow(Math.Abs(b.y - a.y), 2)));
start_a = stop_a;
stop_a = start_a + shapeLength;
dt.Rows.Add(Shape, a.x, a.y, b.x, b.y, shapeLength, start_a, stop_a);
}
}
}
}