ThinkGeo.com    |     Documentation    |     Premium Support

Editing Shapefiles

how do i edit an existing shapefile?  ive used the code below to add a google map layer then load my shapefile using the shapefilefeaturelayer. 


 




Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
                Map1.MapUnit = GeographyUnit.Meter;

                Map1.MapTools.OverlaySwitcher.Enabled = true;
                Map1.MapTools.MouseCoordinate.Enabled = true;

                GoogleOverlay google = new GoogleOverlay("Google Map");
                google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
                google.GoogleMapType = GoogleMapType.Normal;

                ShapeFileFeatureLayer shapeFileFeatureLayer = new ShapeFileFeatureLayer(@"c:\GIS Data\md_sa.shp");
                shapeFileFeatureLayer.RequireIndex = false;
                shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, 212, 220, 184), GeoColor.FromArgb(255, 132, 132, 154), 1);
                shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                Proj4Projection proj4 = new Proj4Projection();
                proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
                shapeFileFeatureLayer.FeatureSource.Projection = proj4;

                LayerOverlay shapeOverlay = new LayerOverlay("Shape Overlay", false, TileType.SingleTile);
                shapeOverlay.Layers.Add(shapeFileFeatureLayer);
                shapeOverlay.TransitionEffect = TransitionEffect.None;

                Map1.CustomOverlays.Add(google);
                Map1.CustomOverlays.Add(shapeOverlay);










Hi Neeraj,


 


Thanks for your post.


 


You could edit an existing shapefile by the edit tool of the ShapeFileFeatureLayer, the code is like this:


 



shapeFileFeatureLayer.Open();
shapeFileFeatureLayer.EditTools.BeginTransaction();
shapeFileFeatureLayer.EditTools.Add(new Feature());
shapeFileFeatureLayer.EditTools.Update(new Feature());
shapeFileFeatureLayer.EditTools.Delete("1");
shapeFileFeatureLayer.EditTools.CommitTransaction();
shapeFileFeatureLayer.Close();

Hope this helps and any more questions please let us know.


 


Thanks,


 


Sun








Below is an image of my shapefile loaded as a layer on Google maps. Ive tried to use the code above but it doesnt seem to take the shapefile layer into an edit mode. Is this possible? I require the shapefile to be editable with the user able to edit points on the shapefile then save the changes. 


 












Sorry Neeraj, I thought you just want to add, delete or update some feature for a shape file. If you want to set all the features in a shape file to edit mode, I think you should get all the features and add them to EditOverlay first, the code could be like this:


 



// Retrieve your shape file feature layer.
ShapeFileFeatureLayer layer = ((LayerOverlay)Map1.CustomOverlays[1]).Layers[0] as ShapeFileFeatureLayer;
layer.Open();
Collection<Feature> features = layer.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns);
foreach (Feature feature in features)
{
    Map1.EditOverlay.Features.Add(feature);
}
layer.Close();

Map1.EditOverlay.TrackMode = TrackMode.Edit;

 


Then, you will see some control points when you mouse click on a feature which is in edit mode. You can edit the feature by the control points. At last, you editing just takes effect on the feature in EditOverlay, so you should get the edit feature from the EditOverlay and save it to the original shape file.


 


Hope this helps and any more questions about this please let us know.


 


Thanks,


 


Sun