This project is read-only.

polygon drawing

Mar 1, 2012 at 9:31 AM

Hi guys. I am new to the Dotspatial.

I am working with my project using Dotspatial. I want to draw lines and polygons on my map interface. I programmed all the code based on the provided tutorial.

the code for drawing line is working perfectly, but there is some problem with polygon drawing.


the code i have used for my software is:

 FeatureSet PolyF;

PolyF = new FeatureSet(FeatureType.Polygon);

 PolyF.Projection = map1.Projection;

  DataColumn polid = new DataColumn("ID");     

 DataColumn polname = new DataColumn("Name");


            polyLayer =(MapPolygonLayer) map1.Layers.Add(PolyF);           

PolygonSymbolizer polysymb = new PolygonSymbolizer(Color.Coral,Color.Chocolate,3);
            polyLayer.Symbolizer = polysymb;           

polyLayer.LegendText = "Polygon"+polyID.ToString();



and on the map1_mouse down event i have written following code:


Coordinate cd = map1.PixelToProj(e.Location); 



             List<Coordinate> polyarray = new List<Coordinate>();                     

                        LineString polygem = new LineString (polyarray);

                        IFeature polyfeature = PolyF.AddFeature(polygem);         

                        polyID +=1;

                  clickone = false;



IFeature existf = PolyF.Features[PolyF.Features.Count - 1];     

                        if(existf.Coordinates.Count >= 2) 

                      {                            PolyF.InitializeVertices();   





else if(e.Button== MouseButtons.Right)       


      clickone = true;               


                    MessageBox.Show("The polygon has been saved!!");     

              map1.Cursor = Cursors.Arrow;         




but this code is not working.

Can anyone please suggest something??

Mar 1, 2012 at 9:51 AM

I have solved the problem :

the code is same except the minor change of the name of the column for polygon ID