LineLengthCS - sindizzy/DSW GitHub Wiki

Sample code that will generate random an array of coordinates, creates a linestring from the array of coordinates, and calculates the length of the linestring.

using DotSpatial.Geometries;
using DotSpatial.Topology.Geometries;

public void PolgygonHolesSC()
{
    //Creates a coordinate arrary
    Coordinate[]() coords = new Coordinate[36](36);
    //Creates a random number generator
    Random rnd = new Random();
    //A for loop that will generate random coordinate's and add those coordinates to the array
    for (int i = 0; i < 36; i++)
    {
        coords[i](i) = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

    }
    //Creates a linestring from the array of coordinates
    LineString ls = new LineString(coords);
    //Calculates the length of the linestring
    Double length;
    length = ls.Length;

}