Skip to content
sindizzy edited this page Dec 30, 2020 · 3 revisions

Sample code that demonstrates how to create a new mulitpolygon from randomly generated coordinates

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

 private void button1_Click(object sender, EventArgs e)
{
    Random rnd = new Random();
    Polygon[]() pg = new Polygon[50](50);
    for (int i = 0; i < 50; i++)
    {
        Coordinate center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
        Coordinate[]() coord = new Coordinate[36](36);
        for (int ii = 0; ii < 36; ii++)
        {
            coord[ii](ii) = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
        }
        coord[35](35) = new Coordinate(coord[0](0)(0).X, coord[0](0)(0).Y);
        pg[i](i) = new Polygon(coord);
    }
    MultiPolygon mpg = new MultiPolygon(pg);
}
Clone this wiki locally