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");

      PolyF.DataTable.Columns.Add(polid);   

        PolyF.DataTable.Columns.Add(polname);
            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); 

       if(clickone)                 

       {                       

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

                        LineString polygem = new LineString (polyarray);

                        IFeature polyfeature = PolyF.AddFeature(polygem);         

              polyfeature.Coordinates.Add(cd);
                        polyID +=1;
                        polyfeature.DataRow["PolyID"]=polyID;     

                  clickone = false;
           }                   

      else                   

    {                       

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

             existf.Coordinates.Add(cd);
                        if(existf.Coordinates.Count >= 2) 

                      {                            PolyF.InitializeVertices();   

                        map1.ResetBuffer();         

                    }                 

  }             

  }               

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

        {             

      clickone = true;               

    map1.ResetBuffer();               

    PolyF.SaveAs("D:\\Shapefiles\\plyshape\\polygon"+polyID.ToString()+".shp",true);
                    MessageBox.Show("The polygon has been saved!!");     

              map1.Cursor = Cursors.Arrow;         

          polydrawn=true;           

    }

 

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

 polyfeature.DataRow["ID"]=polyID;