Sample code that demonstrates how to create a Multi Polygon Feature Set

using DotSpatial.Data;
using DotSpatial.Topology;

        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            Polygon[] pg = new Polygon[100];
            Feature f = new Feature();
            FeatureSet fs = new FeatureSet(f.FeatureType);
            for (int i = 0; i < 100; i++)
            {
                Coordinate center = new Coordinate((rnd.Next(50) * 360) - 180, (rnd.Next(60) * 180) - 90);
                Coordinate[] coord = new Coordinate[50];
                for (int ii = 0; ii < 50; ii++)
                {
                    coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10);
                }
                coord[35] = new Coordinate(coord[0].X, coord[0].Y);
                pg[i] = new Polygon(coord);
                fs.Features.Add(pg[i]);
            }
            fs.SaveAs("C:\\Temp\\test.shp", true);
        }

Last edited Aug 3, 2012 at 8:19 PM by mudnug, version 3

Comments

dannyman939 Mar 1 at 4:05 PM 
the line pg[i] = new Polygon(coord);
throws and exception saying TypeInitializationException unhandled