在Arcgis engine中编辑面要素代码实现
时间: 2024-01-24 20:19:22 浏览: 108
ArcEngine要素编辑
5星 · 资源好评率100%
在ArcGIS Engine中编辑面要素可以使用以下代码实现:
1. 首先,创建一个编辑工具栏并添加面编辑工具:
```csharp
// 创建编辑工具栏
ICommandPool cmdPool = new CommandPoolClass();
UID uid = new UIDClass();
uid.Value = "esriControls.ControlsEditingToolbar";
ICommandItem cmdItem = cmdPool.Find(uid, false);
ICommandBar cmdBar = cmdItem.CommandBar;
cmdBar.Dock(esriDockFlags.esriDockRight);
// 添加面编辑工具
UID editUID = new UIDClass();
editUID.Value = "esriControls.ControlsEditingSketchToolControl";
ICommandItem editCmd = cmdPool.Find(editUID, false);
cmdBar.Add(editCmd);
```
2. 在地图控件上启用编辑模式:
```csharp
axMapControl1.CurrentTool = null;
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
axMapControl1.Enabled = true;
axMapControl1.ShowEditor(true);
axMapControl1.CurrentTool = editCmd.Command;
```
3. 实现面要素的创建和编辑:
```csharp
// 创建新面要素
IWorkspaceEdit workspaceEdit = ((IDataset)featureLayer.FeatureClass).Workspace as IWorkspaceEdit;
workspaceEdit.StartEditing(false);
workspaceEdit.StartEditOperation();
IFeature newFeature = featureLayer.FeatureClass.CreateFeature();
newFeature.Shape = new PolygonClass();
IPointCollection pointCollection = newFeature.Shape as IPointCollection;
pointCollection.AddPoint(new PointClass() { X = x1, Y = y1 });
pointCollection.AddPoint(new PointClass() { X = x2, Y = y2 });
// ... 添加更多点
newFeature.Store();
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
// 编辑现有面要素
IEditor editor = axMapControl1.Map as IEditor;
editor.StartEditing(featureLayer.FeatureClass.Workspace);
editor.StartOperation();
editor.ModifyFeature(newFeature, pointCollection as IGeometry);
editor.StopOperation("Edit Polygon");
```
注意,以上代码仅为示例,需要根据具体情况进行修改和完善。
阅读全文