[GIS] Editing shapefile in ArcMap programmatically

arcgis-desktoparcobjectsc

Is this something that can be done?

For instance if I created an overlay on a map and saved it as a shapefile, I want to go and edit this (pre-existing file.) overlay… Either add points/remove points change color/fillstyle/etc.

Ideally I want to avoid creating a new shapefile and deleting the old one.

Thoughts?

Edit 1: OK, now that someone has said it can be done. The obvious question is, how do you edit the shapefile (in ArcObjects pro-grammatically)?

Edit 2: Looking at comments it appears I need to do something like this, but I'm not sure.

I currently have a basic shapefile that I want to edit in ArcObjects in C#.

I've created a shapefile by creating a FeatureClass , Workspace and then obviously passing in my shape. In this case it's just a simple Polyline with a few points on it. What I'd like to do is have the ability to update this shapefile.

I'm assuming I need to re-use that FeatureClass, Workspace and pass in a new shape. However, what I'm doing doesn't seem to work. This is where I'm at on the edit – any advice would be great.

IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)inWorkspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();

ComReleaser comReleaser = new ComReleaser();

IFeatureCursor featureCursor = inFeatureClass.Update(null , true);

IFeature feature = null;
while((feature = featureCursor.NextFeature()) != null)
{
   int id = feature.Fields.FindField("shape");
   IFeatureBuffer featureBuffer = inFeatureClass.CreateFeatureBuffer();
   featureCursor.DeleteFeature(); //Delete the old 
   featureBuffer.Shape = (IGeometry)inShape;
   featureCursor.InsertFeature(featureBuffer);
}

workspaceEdit.StopEdidtOperation();
workspaceEdit.StopEditing(true);

EDIT 3:
Final Solution

featureCursor = inFeatureClass.Update(null ,true);
//DELETE old shape
featureCursor = inFeatureClass.Insert(true);
//Insert new 
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);

Best Answer

I created and manipulated a shapefile programmatically - so maybe this can provide some hints for adding points: save IGeometry to disk as a Layer file

As for coloring a layer, that's pretty simple.

IGeoFeatureLayer geolayer = thislayer as IGeoFeatureLayer;
ISimpleRenderer simplerenderer = geolayer.Renderer as ISimpleRenderer;
if (simplerenderer != null)
{
//depending on the type one of these objects will probably not be null -- then set .Color and .Symbol 

IMarkerSymbol markersymbol = simplerenderer.Symbol as IMarkerSymbol;
ILineSymbol linesymbol = simplerenderer.Symbol as ILineSymbol;
SimpleFillSymbol simpleFillSymbol = simplerenderer.Symbol as SimpleFillSymbol;
}
Related Question