arcgis engine中删除指定元素
时间: 2023-07-30 19:12:40 浏览: 199
ArcGIS-Engine基础开发教程(C#)C#二次开发ArcGis.pdf
5星 · 资源好评率100%
在 ArcGIS Engine 中删除指定元素,可以使用以下方法:
1. 获取要素图层对象:
```c#
IFeatureLayer featureLayer = mapControl1.Map.get_Layer(layerIndex) as IFeatureLayer;
```
2. 根据要素 ID 获取要素对象:
```c#
IFeature feature = featureLayer.FeatureClass.GetFeature(featureID);
```
3. 使用编辑对象获取编辑工作空间:
```c#
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)((IDataset)featureLayer.FeatureClass).Workspace;
```
4. 启动编辑操作:
```c#
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
```
5. 删除要素对象:
```c#
feature.Delete();
```
6. 结束编辑操作:
```c#
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
```
完整代码示例:
```c#
IFeatureLayer featureLayer = mapControl1.Map.get_Layer(layerIndex) as IFeatureLayer;
IFeature feature = featureLayer.FeatureClass.GetFeature(featureID);
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)((IDataset)featureLayer.FeatureClass).Workspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
feature.Delete();
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
```
阅读全文