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.


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;

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;


EDIT 3: Final Solution

featureCursor = inFeatureClass.Update(null ,true);
//DELETE old shape
featureCursor = inFeatureClass.Insert(true);
//Insert new 
  • Are you saying that you drew some annotation layers on the map with ArcMap's drawing tools? If you converted that to a shape file, you can definitely edit it as if it were a shapefile. – jvangeld Mar 7 '11 at 20:12
  • I'm using the ArcMap.TrackPolygon to create an IPolygon and then I eventually turn that into a shape file. What I want to do then is edit this shapefile....I know how to get the properties (points, fillstyle, color, etc) – ist_lion Mar 7 '11 at 20:28
  • 1
    So in ArcObjects pro-grammatically? – Mapperz Mar 7 '11 at 20:48
  • Yes that's what I'd like to do – ist_lion Mar 7 '11 at 20:53
  • Thanks for sharing the solution, fyi if you tag with C# you will get syntax highlighting. – patrick Mar 8 '11 at 21:58

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;
| improve this answer | |
  • Hmm, perhaps I'm not wording this question correctly. I can already create and save a shape file programmatically . What I want to do is edit this pre-existing file. I'm guessing the same logic will work though.... – ist_lion Mar 8 '11 at 13:21
  • 1
    @PSU_Kardi I think you have to use featureCursor.InsertFeature(fb); and featureCursor.DeleteFeature to edit your pre-existing file – patrick Mar 8 '11 at 14:39
  • I'll look into it - I think that's what I want – ist_lion Mar 8 '11 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.