ThinkGeo.com    |     Documentation    |     Premium Support

Editing Shape Files

When working with shape files at street level I would like to make modifications to the shape file dynamically.  Say I see a street is missing on one of my maps and want to include that.  Are there methods that allow you to draw a line on the screen and have it update the shape file accordingly? 


I would also like to add other shapes to the maps, these would be stored in a database with GPS reference points.  If I move one of the houses, how simple is it to gather the new GPS coordinates to update the database with? 


 


Jake



Jake, 
  
 I think it’s difficult to include a missing street as it’s almost impossible to locate with mouse exactly the position you want. If you you can get the 2 points, you can easily add that missing street programally though. We might add Snapping in Desktop and it will be much easier even with mouse then. 
  
 Here is the code how to get features from the TrackOverlay and add them to a shape file. 
  
 
ShapeFileFeatureLayer targetEditLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer(“WorldLayer”);
winformsMap1.Overlays[“Overlay1”].Lock.EnterWriteLock();

targetEditLayer.Open();
try
{
                targetEditLayer.EditTools.BeginTransaction();
                foreach (Feature feature in winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)
                {
                    targetEditLayer.EditTools.Add(feature);
                }
                TransactionResult result = targetEditLayer.EditTools.CommitTransaction();

                if (result.TotalFailureCount > 0)
                {
                    MessageBox.Show(“Edit error”);
                }
            }
            finally
            {
                targetEditLayer.Close();
                winformsMap1.Overlays[“Overlay1”].Lock.ExitWriteLock();
            }
            winformsMap1.Refresh();
 
  
 It’s very easy to update your shape in a database. The code is almost the same as above, get the updated feature from TrackOverlay and then update the corresponding shape in the database. You need to replace ShapeFileFeatureLayer with MsSql2008FeatureLayer for example and use the method Update instead of Add, will be fine. 
  
 Hope it helps. 
  
 Ben