LFCS - sindizzy/DSW GitHub Wiki

This code generates a random linestring from a coordinate array using the Geometry library then creates a line feature using the desktop library.

using DotSpatial.Data;
using DotSpatial.Topology;

namespace SampleCode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Creates a random number generator
            Random rnd = new Random();
            //creates a new coordiante array
            Coordinate[]() c = new Coordinate[36](36);
            //for loop that will generate 36 random numbers
            for (int i = 0; i < 36; i++)
            {
                c[i](i) = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            }
            //creates a linestring from the coordinate array
            LineString ls = new LineString(c);
            //creates a feature from the linestring
            Feature f = new Feature(ls);
            FeatureSet fs = new FeatureSet(f.FeatureType);
            fs.Features.Add(f);

    }
}