circle shape creation

Feb 11, 2011 at 10:19 AM

Hi,

i want to create a polygon shapefile, in which i want to add circle shapes...

anybody can help me about it? A coded example will be good!

Thanks

Seum

Developer
Feb 12, 2011 at 4:12 PM

This sample code could help I suppose. 

    private void btnCreatePolygons_Click(object sender, EventArgs e)

        {
            MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile();
            bool result = sf.CreateNewWithShapeID("", MapWinGIS.ShpfileType.SHP_POLYGON);

            if (!result)
            {
                MessageBox.Show(sf.get_ErrorMsg(sf.LastErrorCode));
            }
            else
            {
                double xMin = 0.0;
                double yMin = 0.0;
                double xMax = 1000.0;
                double yMax = 1000.0;
                Random rnd = new Random(DateTime.Now.Millisecond);

                for (int i = 0; i < 10; i++)
                {
                    double xCenter = xMin + (xMax - xMin) * rnd.NextDouble();
                    double yCenter = yMin + (yMax - yMin) * rnd.NextDouble();

                    // random radius from 10 to 100
                    double radius = 10 + rnd.NextDouble() * 90;
                    
                    MapWinGIS.Shape shp = new MapWinGIS.Shape();
                    shp.Create(MapWinGIS.ShpfileType.SHP_POLYGON);

                    for (int j = 0; j < 36; j++)
                    {
                        MapWinGIS.Point pnt = new MapWinGIS.Point();
                        pnt.x = xCenter + radius * Math.Cos(j * Math.PI / 18);
                        pnt.y = yCenter - radius * Math.Sin(j * Math.PI / 18);
                        shp.InsertPoint(pnt, ref j);
                    }
                    sf.EditInsertShape(shp, ref i);
                }
                
                axMap1.AddLayer(sf, true);
                axMap1.ZoomToLayer(0);

                if (!sf.Save(null))
                {
                    MessageBox.Show(sf.get_ErrorMsg(sf.LastErrorCode));
                }
            }
        }