ArcEngine要素编辑遇到的一些问题
1、如何开启编辑
IMap myMap = this._Aplication.ActiveView.FocusMap;
IWorkspace myWorkspace = (myMap25Sheet.PointFeatureLayer as IDataset).Workspace;
this._Aplication.EngineEditor.EnableUndoRedo(true);
this._Aplication.EngineEditor.StartEditing(myWorkspace, myMap);
this._Aplication.EngineEditor.StartOperation();
2、如何设置要编辑的目标图层
IEngineEditLayers myEngineEditLayers = this._Aplication.EngineEditor as IEngineEditLayers;
myEngineEditLayers.SetTargetLayer(myMap25Sheet.PointFeatureLayer, 0);
3、编辑的不符合规则,如何回退
IWorkspaceEdit myWorkspaceEdit = this._Application.EngineEditor.EditWorkspace as IWorkspaceEdit;
bool myHasUndo = false;
myWorkspaceEdit.HasUndos(ref myHasUndo);
if (myHasUndo == true)
{
IMap myMap = this._Application.ActiveView.FocusMap;
((IActiveView)myMap).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
myMap.ClearSelection();
((IActiveView)myMap).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
myWorkspaceEdit.UndoEditOperation();
this._Application.ActiveView.Refresh();
}
注意,一定要调用清空选择那块的代码,不然回退后,刷新下地图,又会重新回来,发现这个问题花了好长时间。
4、如何控制只能选择和编辑一个要素
private void EngineEditor_OnSelectionChanged() { Map25Sheet myMap25Sheet = this._Application.WorkZone.ActiveMap25Sheet; if (myMap25Sheet == null) { this._Application.SamplePointInfoUI.SetPointFeature(null); return; } IFeatureLayer myFeatureLayer = myMap25Sheet.PointFeatureLayer; IFeatureSelection myFeatureSelection = myMap25Sheet.PointFeatureLayer as IFeatureSelection; if (myFeatureSelection.SelectionSet.Count == 0) { this._Application.SamplePointInfoUI.SetPointFeature(null); return; } int myID = myFeatureSelection.SelectionSet.IDs.Next(); if (myFeatureSelection.SelectionSet.Count > 1) { myFeatureSelection.Clear(); myFeatureSelection.SelectionSet.Add(myID); } this._Application.SamplePointInfoUI.SetPointFeature(myFeatureLayer.FeatureClass.GetFeature(myID)); this._Application.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
EngineEditor的OnSelectionChanged事件,在这控制下即可。
5、如何只编辑一个图层
控制其他图层不能不能被选择即可。
myFeatureLayer.Selectable = false;
6、ArcEngine中没有保存函数,如何保存编辑
先停止编辑,调用停止的时候,把是否保存参数设置为true,然后再重新开启即可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理