Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is this something that can be done?

For instance if I created an overlay on a map and saved it as a shape file, 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 shp file 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 shape file (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 shape file 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);
share|improve this question
    
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) –  PSU_Kardi 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 –  PSU_Kardi 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
add comment

1 Answer

up vote 4 down vote accepted

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;
}
share|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.... –  PSU_Kardi 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 –  PSU_Kardi Mar 8 '11 at 17:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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