ThinkGeo.com    |     Documentation    |     Premium Support

Create ShapeFile polygon

I want to create a ShapeFile containing polygons with XY coordinates from long and lat GPS coordinates. I get the the error: "wellKnownText  Parameter name: The shape you provided does not pass our simple validation."


Dim polygonShape = New MapSuite.Core.PolygonShape("Polygon((30.081 -26.632, 30.09 -26.629, 30.094 -26.638, 30.086 -26.64 ))" )


Please assist me.



Ok, here is all my code. Please help me to solve my two problems: 
  
 1) It works when I use: xy = “Polygon((-40 0, -40 20, -10 20, -40 0))” but I get the “wellKnownText” error when I use: xy = “Polygon((30.090728 -26.648588, 30.098243 -26.645768, 30.103212 -26.653944, 30.095499 -26.656581))”.  Surely a polygon is not always a rectangle. 
  
 2) The shp file gets created with one field (ZONE_ID), how do I add more fields:  X1, Y1 …  up to X4, Y4 ? 
  
             'get the data 
             CL_TCO_ZONESTableAdapter.Fill(DataSet1.CL_TCO_ZONES) 
  
             'define the column in the shape file  
             Dim idColumn As New MapSuite.Core.DbfColumn(“ZONE_ID”, DbfColumnType.String, 8, 0) 
  
             'create the shape file 
             MapSuite.Core.ShapeFileFeatureSource.CreateShapeFile(ShapeFileType.Polygon, _ 
                                                                  “c:\abc.shp”, _ 
                                                                  New DbfColumn() {idColumn}) 
  
             'create the index file 
             MapSuite.Core.ShapeFileFeatureSource.BuildIndexFile(“c:\abc.shp”) 
  
             'open the blank shaped file 
             Dim zoneShapeFile As New MapSuite.Core.ShapeFileFeatureSource(“c:\abc.shp”, ShapeFileReadWriteMode.ReadWrite) 
             zoneShapeFile.Open() 
  
             'begin the transaction  
             zoneShapeFile.BeginTransaction() 
  
             'read the dataset and add the coordinates to the shape file 
             Dim rowView As System.Data.DataRowView 
             Dim row As DataSet1.CL_TCO_ZONESRow 
             CL_TCO_ZONESBindingSource.MoveFirst() 
  
                 rowView = Me.CL_TCO_ZONESBindingSource.Current 
                 row = rowView.Row 
  
                     Dim xy As String = “” 
  
                     'xy = “Polygon((30.090728 -26.648588, 30.098243 -26.645768, 30.103212 -26.653944, 30.095499 -26.656581))” 
  
                     xy = “Polygon((-40 0, -40 20, -10 20, -40 0))” 
  
                     Dim polygonShape = New PolygonShape(xy) 
  
                     Dim zoneColumns As New Dictionary(Of String, String) 
                     zoneColumns.Add(“ZONE_ID”, row.ZONE_ID.ToString) 
                     zoneColumns.Add(“X1”, -40) 'row.X1.ToString) 
                     zoneColumns.Add(“Y1”, 0) 'row.Y1.ToString) 
                     zoneColumns.Add(“X2”, -40) 'row.X2.ToString) 
                     zoneColumns.Add(“Y2”, 20) 'row.Y2.ToString) 
                     zoneColumns.Add(“X3”, -10) 'row.X3.ToString) 
                     zoneColumns.Add(“Y3”, 20) 'row.Y3.ToString) 
                     zoneColumns.Add(“X4”, -40) 'row.X4.ToString) 
                     zoneColumns.Add(“Y4”, 0) 'row.Y4.ToString) 
  
                     Dim feature As New MapSuite.Core.Feature(polygonShape, zoneColumns) 
                     zoneShapeFile.AddFeature(feature) 
  
             'commit the transaction and close the file 
             Dim results As TransactionResult = zoneShapeFile.CommitTransaction 
             MessageBox.Show("Features added to zone shapefile result: " & results.TransactionResultStatus.ToString) 
             zoneShapeFile.Close()

Alta, 
  
 1, The first point should be identical with the last point for a ring in WKT, I think that’s why one of your WKT passes while the other could not. 
  
 2, After a shp file is created, it is not recommended to add another fields to the corresponding dbf , bacause the efficiency is very low. Instead, you can add a new column “virtually” to the source data with the event FeatureSource.CustomColumnFetch. In that way, the source of new data will be transparent and you can just imagine all the data is from a simple shape file. Please have a look at the sample “Feature Layers”->AddMyOwnCustomDataToAFeatureLayer for detail. 
  
 Hope that helps, any queries please let us know. 
  
 Ben

Thanks

Let me know for any queries.