以编程方式在ArcMap中编辑shapefile?


9

这是可以做到的吗?

例如,如果我在地图上创建了一个叠加层并将其另存为shapefile,我想去编辑该(预先存在的文件。)叠加层...添加点/删除点都会更改颜色/ fillstyle / etc。

理想情况下,我想避免创建新的shapefile并删除旧的shapefile。

有什么想法吗?

编辑1:好,既然有人说可以做到。显而易见的问题是,如何编辑shapefile(在ArcObjects中以编程方式)?

编辑2:看评论,我似乎需要做这样的事情,但我不确定。

我目前有一个基本的shapefile,我想在C#的ArcObjects中进行编辑。

我通过创建FeatureClass,Workspace并随后传入我的形状来创建了shapefile。在这种情况下,它只是一条简单的折线,上面有一些点。我想做的就是能够更新此shapefile。

我假设我需要重用FeatureClass,Workspace并传递新形状。但是,我在做什么似乎不起作用。这就是我在进行编辑的地方-任何建议都很棒。

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);

编辑3: 最终解决方案

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

您是在说用ArcMap的绘图工具在地图上绘制了一些注释层吗?如果将其转换为形状文件,则绝对可以像将其作为形状文件一样对其进行编辑。
jvangeld 2011年

我使用ArcMap.TrackPolygon创建IPolygon,然后最终将其转换为形状文件。然后我想做的就是编辑这个shapefile。...我知道如何获取属性(点,填充样式,颜色等)
ist_lion 2011年

1
那么在ArcObjects中以编程方式进行?
Mapperz

是的,这就是我想要做的
ist_lion

感谢您共享解决方案,如果您使用C#进行标记,则会突出显示语法。
帕特里克

Answers:


4

我以编程方式创建和操纵了shapefile-也许这可以为添加点提供一些提示:将IGeometry作为Layer文件保存到磁盘

至于给图层着色,这很简单。

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;
}

嗯,也许我的措词不正确。我已经可以通过编程方式创建和保存形状文件。我想要做的是编辑此现有文件。我猜相同的逻辑会的工作,虽然....
ist_lion

1
@PSU_Kardi我认为您必须使用featureCursor.InsertFeature(fb); 和featureCursor.DeleteFeature来编辑您先前存在的文件
patrick

我会考虑它-我想这就是我想要的东西
ist_lion
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.