版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
GIS应用开发DevelopingGISApplicationswithArcObjectsusingC#.NET
空间数据编辑(6学时)ArcGISEngine编辑概述版本化空间数据编辑DisplayFeedback对象多边形挖空处理分割线要素线、面要素整形(Reshape)要素合并多部分要素的处理线要素的延伸与修剪10.1OverviewofArcGISEngineeditingArcGISEngine编辑与ArcMap编辑编辑流程
编辑目标图层(Editingtargetlayer)编辑任务(Edittasks)编辑绘制(Editsketch)使用操作栈(Workingwiththeoperationstack)使用捕捉环境编辑事件要素查看器(Featureinspectors)使用要素模板10.1.1
ArcGISEngine编辑与ArcMap编辑ArcGIS桌面的编辑功能通过Editor库发布,
ArcGISEngine的编辑功能包含在Controls
库中.
ArcGISEngine
Controls库中提供了内置的编辑命令、工具、菜单等,用于地理要素的复制、剪切、粘贴和删除、启动编辑、停止编辑、保存编辑、编辑工具(EditTool)、绘制工具(SketchTool)、编辑的目标图层ToolControl、属性编辑、要素编辑过程中右键菜单功能和Snapping设置等功能。这些命令、工具等在开发过程中可以直接使用。要素的复制、剪切、粘贴和删除ControlToolsEditing_Copy{2D7BD886-7531-4198-820D-551A5A14569E}esriControls.ControlsEditingCopyCommandControlToolsEditing_Cut{C03E7512-CA4E-4197-8386-57830425D13A}esriControls.ControlsEditingCutCommandControlToolsEditing_Paste{99FADFFD-A788-4F1F-A1B3-04909B06735A}esriControls.ControlsEditingPasteCommandControlToolsEditing_Clear{C4CB4830-8C2E-49AE-9D12-73E822BCA90E}esriControls.ControlsEditingClearCommandArcGISEngine环境下的EditorToolbar、EditorMenuandEditTask:ControlToolsEditing_Start{5CAF45CD-E3B1-4FFD-96C4-BCDD2289C1EB}esriControls.ControlsEditingStartCommandControlToolsEditing_Stop{8D03C271-BB00-4A36-9B84-AD2E1DE0DE11}esriControls.ControlsEditingStopCommandControlToolsEditing_Save{0BB6A923-6AAF-4B7A-B8A8-A7225065A0C8}esriControls.ControlsEditingSaveCommandControlToolsEditing_Edit{6F922BD8-EF26-4852-BAED-45CFF3A97121}esriControls.ControlsEditingEditToolControlToolsEditing_Sketch{13B234E8-3B30-49CA-9967-4C76F7231AD6}esriControls.ControlsEditingSketchToolControlToolsEditing_TargetToolControl{5D815B27-6A93-42DB-B2C6-1CC58B416E9F}esriControls.ControlsEditingTargetToolControlControlToolsEditing_Attribute{A554ADBC-D0DD-469A-8A95-B4CEED0794C3}esriControls.ControlsEditingAttributeCommandControlToolsEditing_SketchProperties{506ACF9B-B4B4-4A4A-A5FA-5215E4A240B2}esriControls.ControlsEditingSketchPropertiesCommand撤销(undo)/重复(redo)ControlToolsGeneric_Redo{B0675372-0271-4680-9A2C-269B3F0C01E8}esriControls.ControlsRedoCommandControlToolsGeneric_Undo{380FB31E-6C24-4F5C-B1DF-47F33586B885}esriControls.ControlsUndoCommandArcGISEngine的“SketchToolContextMenu”ControlToolsEditing_SnapToFeatureMenu{3E28536E-66EB-4812-BD8C-7AE6EA5CCB17}esriControls.ControlsEditingSnapToFeatureMenuControlToolsEditing_SnapEndpoint{B473F50B-3D6B-4718-8DE3-75D7ECACED58}esriControls.ControlsEditingSnapEndpointCommandControlToolsEditing_SnapVertex{78FF7F24-E5E6-4CA4-993E-6FAA81684441}esriControls.ControlsEditingSnapVertexCommandControlToolsEditing_SnapMidpoint{250219D8-7A0B-4017-93EF-1E893D16F742}esriControls.ControlsEditingSnapMidpointCommandControlToolsEditing_SnapEdge{5D67D843-E10C-4D0B-A69C-2DFA82B25450}esriControls.ControlsEditingSnapEdgeCommandControlToolsEditing_SketchDirection{4E6E4BB5-4B2E-4E1F-8E08-18E24FF80A13}esriControls.ControlsEditingSketchDirectionCommandControlToolsEditing_SketchDeflection{3ECE8CAB-3DAD-4B04-B586-D9B6369885C3}esriControls.ControlsEditingSketchDeflectionCommandControlToolsEditing_SketchLength{FAF9D507-97DF-4F2E-835A-35A3DECF90B9}esriControls.ControlsEditingSketchLengthCommandControlToolsEditing_SketchChangeLength{6EF1BE13-4FF4-4529-958D-46A418C99DD8}esriControls.ControlsEditingSketchChangeLengthCommandControlToolsEditing_SketchAbsoluteXY{B368783B-9BDE-46A6-A712-2969C1F21FA2}esriControls.ControlsEditingSketchAbsoluteXYCommandControlToolsEditing_SketchDeltaXY{061BD3E1-4245-4699-863C-DE478647FBE3}esriControls.ControlsEditingSketchDeltaXYCommandControlToolsEditing_SketchDirectionLength{9DB473E5-BF90-465B-8758-74C656F136EB}esriControls.ControlsEditingSketchDirectionLengthCommandControlToolsEditing_SketchParallel{798FED0C-978D-4DFA-A658-D3DADF9D414D}esriControls.ControlsEditingSketchParallelCommandControlToolsEditing_SketchPerpendicular{A9F4EAD1-622C-4BC7-857B-55ABA51D5359}esriControls.ControlsEditingSketchPerpendicularCommandControlToolsEditing_SketchSegmentDeflection{A1D97BFF-5B08-4852-8223-5714EC5811DB}esriControls.ControlsEditingSketchSegmentDeflectionCommandControlToolsEditing_SketchReplace{C9DFFED3-57CC-485A-A5A1-CC510CE9DC97}esriControls.ControlsEditingSketchReplaceCommandControlToolsEditing_SketchStreaming{4E8F7A0A-C3F3-462B-9632-D9981941A18E}esriControls.ControlsEditingSketchStreamingCommandControlToolsEditing_SketchDelete{E5D330C9-8E98-4148-818F-7128D152DFD5}esriControls.ControlsEditingSketchDeleteCommandControlToolsEditing_SketchFinish{2A876779-8A6A-4B73-9B89-AE0099B0571A}esriControls.ControlsEditingSketchFinishCommandControlToolsEditing_SketchFinishSquare{73883500-776E-4E99-92B2-6ED6332558DD}esriControls.ControlsEditingSketchFinishSquareCommandControlToolsEditing_SketchFinishPart{D69E981F-4FDE-4077-B224-0C58A35AF668}esriControls.ControlsEditingSketchFinishPartCommandControlToolsEditing_TaskToolControl{BEB77C7B-4257-41DC-9447-C3C5C4C8F7C7}esriControls.ControlsEditingTaskToolControl在ArcGIS桌面环境中的主要编辑对象是Editor,而在ArcGISEngine开发中则是EngineEditor(单实例对象);在相应的应用程序中,它们负责管理编辑绘制(editsketch)、当前任务(currenttask)、当前目标图层(currenttargetlayer)、编辑工作空间(editworkspace)、编辑选择(editselection)、编辑会话属性(editsessionproperties)以及捕捉环境(snapenvironment)。EngineEditor主要接口有:IEngineEditor、IEngineEditLayers、IEngineEditProperties、IEngineEditProperties2、IEngineEditSketch、IEngineSnapEnvironment、IEngineEditEvents、IExtension(System).表10-1ArcGISEngine与ArcGISDesktop编辑的主要接口比较ArcGISEngineArcGISDesktopEditingenvironmentIEngineEditor(Newin9.3)IEditorEdittasksIEngineEditTask(Newin9.3)IEditTaskEditsketchIEngineEditSketch(Newin9.3)IEditSketchEditlayersIEngineEditLayers(Newin9.3)IEditLayersEditpropertiesIEngineEditPropertiesIEditPropertiesEditeventsIEngineEditEvents(Newin9.3)IEditEventsArcMapEditor主要接口:InterfacesIEditAnnotationPropertiesIEditAttributePropertiesIEditLayersIEditor3IEditorZIEditPropertiesIEditProperties2IEditProperties3IEditProperties4IEditSketch3IEditTaskSearchIExtension(esriSystem)IExtensionAccelerators(esriSystem)IExtensionManager(esriSystem)ISnapEnvironment3IEngineEditSketch
IEngineEditorIEngineEditLayers
IEngineEditProperties
IEngineEditProperties2
IEngineEditEvents
(Newin9.3)IEngineEditTask(newatArcGIS9.3)编辑任务使用编辑绘制几何对象(fromIEngineEditSketch.Geometry)完成某项操作;EngineEditor一次只能有一个活动的编辑任务,使用
IEngineEditor.CurrentTask
设置当前的编辑任务.所有的Engine编辑任务都实现了IEngineEditTask
接口.Engine编辑任务必须注册到‘ESRIEngineEditTasks’组件类目中,以便显示在
ControlsEditingTaskToolControl中.10.1.2编辑流程编辑会话(Editsession)建议所有的编辑操作应该一个编辑会话中完成,当应用程序使用插入游标或更新游标进行批导入或批更新要素除外。一个编辑会话中可以包含多个编辑(Editoperation)和绘制操作(Sketchoperation)。编辑操作用于创建、修改或删除要素,而绘制操作用于修改编辑绘制(editsketch)。编辑与绘制操作可以看作是嵌套在编辑会话对应的长事务中的一系列短事务。通过把每个操作加入操作栈,实现编辑会话中的undo/redo功能。一旦编辑会话完成,所有操作都从操作栈删除。加入到操作栈的绘制操作是暂时的,绘制完成后,一系列的绘制操作将被一个编辑操作取代,编辑会话结束后,操作栈将被清空。使用IEngineEditor
(Controls库)和IWorkspaceEdit
(Geodatabase库)均可创建编辑会话。在不需要用户交互自动完成空间数据编辑功能的应用程序中,应使用IWorkspaceEdit
;反之,在需要用户交互才能完成空间数据编辑的应用程序中,则使用IEngineEditor。启动编辑会话使用IEngineEditor.StartEditing方法启动编辑会话,该方法有一个IMap类型和一个IWorkspace类型的参数。所有来自同一工作空间且处于地图中的可编辑图层均可在编辑会话中进行编辑;IEngineEditLayers.IsEditable
属性可以检测某图层是否可以编辑;在SDE工作空间中,IEngineEditor.EditSessionMode可以指定编辑会话的模式(版本化或非版本化编辑),
versioned和non-versioned图层不能同时在一个编辑会话中编辑。IEngineEditor启动编辑会话:privateIEngineEditorm_engineEditor=newEngineEditorClass();privatevoidStartEditing(IMapmap,IFeatureLayerfeatureLayer){if(m_engineEditor.EditState!=esriEngineEditState.esriEngineStateNotEditing)return;
IDatasetdataset=featureLayer.FeatureClassasIDataset;
IWorkspaceworkspace=dataset.Workspace;m_engineEditor.StartEditing(workspace,map);((IEngineEditLayers)m_engineEditor).SetTargetLayer(featureLayer,-1);}publicvoidSetTargetLayer(
IFeatureLayer
Layer,
int
SubType);执行编辑操作IEngineEditor接口提供了一系列方法用于编辑操作,如StartOperation、AbortOperation及StopOperation。
IEngineEditor.StartOperation--启动编辑操作publicvoidStartOperation();IEngineEditor.AbortOperation--取消编辑操作,不保存编辑publicvoidAbortOperation();IEngineEditor.StopOperation--结束编辑操作publicvoidStopOperation(
stringoperationName);operationName
allowstheoperationtobeidentifiedontheoperatonstack.privatevoidcmdEditOperation()
{m_engineEditor.StartOperation();try
{//Performfeatureeditshere.
if(someEditValidationChecksMethod==true)
m_engineEditor.StopOperation(“Testeditoperation”);
else
m_engineEditor.AbortOperation();
}catch(Exceptionex)
{m_engineEditor.AbortOperation();
//Addcodetohandleexception.
}
}保存编辑结束编辑会话通过执行ControlsEditingSaveCommand命令,可以保存编辑会话中的编辑变化;也可以调用IEngineEditor.StopEditing(saveChanges参数设置为true)方法保存编辑变化,该方法的语法如下:publicvoidStopEditing(
boolsaveChanges);若saveChanges参数为false,则不保存编辑变化结束编辑会话。privatevoidbtnStopEditing_Click(objectsender,EventArgse)
{if(m_engineEditor.HasEdits()==false)m_engineEditor.StopEditing(false);else
{if(MessageBox.Show("SaveEdits?","SavePrompt",MessageBoxButtons.YesNo)==DialogResult.Yes)m_engineEditor.StopEditing(true);elsem_engineEditor.StopEditing(false);
}
}IWorkspaceEdit接口IWorkspaceEdit接口是ArcObjects实现空间数据编辑功能的另一接口.它可以启动或停止一个编辑流程,适用于不需要用户交互的编辑操作。使用StartEditing方法启动一个编辑流程publicvoid
StartEditing(boolwithUndoRedo);withUndoRedo参数用来确定是否支持“undo/redo”功能。在启动编辑后,可以使用StartEditOperation方法开启编辑操作。publicvoidStartEditOperation();如果在编辑过程中出现了异常,可以使用AbortEditoperation方法来取消编辑操作。publicvoidAbortEditOperation();在完成一个编辑后,用户可以使用StopEditoperation方法来确保编辑操作的完成。publicvoidStopEditOperation();UndoEditoperation方法可以用于编辑状态的回滚操作,如果发现编辑过程有误,通过执行这个方法可以恢复到最近变化前的状态。在整个编辑流程完成后,可以使用StopEditing方法来完成编辑。当执行完这个方法后,就意味着不能再进行“恢复/取消恢复”了。publicvoidStopEditing(boolsaveEdits);privatevoidStartEditing
(IFeatureLayerfeatureLayer){IFeatureClassfeatureClass=featureLayer.FeatureClass;
IDatasetdataset=featureClassasIDataset;
IWorkspaceEditworkspaceEdit=dataset.WorkspaceasIWorkspaceEdit;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
IFeaturepFeature=featureClass.GetFeature(1);pFeature.Delete();
workspaceEdit.StopEditOperation();
boolbHasEdits=true;DialogResultiResponse=MessageBox.Show("EditOperation","Undooperation?",MessageBoxButtons.YesNo);if(iResponse==DialogResult.Yes)workspaceEdit.UndoEditOperation();workspaceEdit.HasEdits(refbHasEdits);if(bHasEdits){iResponse=MessageBox.Show("EditOperation","Saveedits?",MessageBoxButtons.YesNo);if(iResponse==DialogResult.Yes){workspaceEdit.StopEditing(true);}else{workspaceEdit.StopEditing(false);}}
}
10.1.3
编辑目标图层使用IEngineEditLayers.SetTargetLayer
或ControlsEditingTargetToolControl设置要编辑的目标图层
。使用IEngineEditLayers.TargetLayer
获得目前编辑的图层。使用IEngineEditEvents.OnTargetLayerChanged
事件来监听编辑目标图层的变化。IEngineEditLayers
10.1.4
编辑任务编辑任务使用编辑绘制中的几何对象(IEngineEditSketch.Geometry)完成某一特定的编辑操作;EngineEditor一次只能有一个活动的编辑任务,使用IEngineEditor.CurrentTask设置当前的编辑任务。所有的Engine编辑任务都实现了IEngineEditTask
接口。Engine编辑任务必须注册到“ESRIEngineEditTasks”组件类目中,以便显示在ControlsEditingTaskToolControl中。EngineEditor提供了两个内置的编辑任务:CreateNewFeature和ModifyFeature.可以通过实现IEngineEditTask接口创建自定义的编辑任务。IEngineEditTask.GroupName
属性允许编辑任务在ControlsEditingTaskToolControl中逻辑分组。使用IEngineEditEvents.OnCurrentTaskChanged
事件监听编辑任务的改变。使用ArcGIS添加类向导(ArcGISAddClassWizard)来快速创建实现IEngineEditTask接口的类,创建定制的编辑任务.Samples:EditingCutPolygonsEditTaskEditingReshapePolylineEditTask10.1.5编辑绘制-EditsketchIEngineEditSketch
中的geometry用于完成当前的编辑任务,如当前编辑任务为“CreateNewFeature”时,使用该geometry来创建一个要素;
geometry由当前编辑任务设置,其类型可以是:amultipoint,apolyline,orapolygon,与目标编辑图层的几何类型相同。IEngineEditSketchAE提供了2个快捷菜单帮助完成editsketchgeometry.ControlsEditingSketchContextMenuControlsEditingVertexContextMenuCreatingasketchoperationIEngineSketchOperation.Start
启动一绘制操作(sketchoperation),使用IEngineSketchOperation.SetMenuString
方法命名该操作,以便操作栈(operationstack)能够识别该操作,并用作Undo/Redo的ToolTip.IEngineSketchOperation.Finish结束一绘制操作,并将该操作放入操作栈中。publicvoidStart(IEngineEditor
editor);publicvoidSetMenuString(string
MenuString);publicvoidFinish
(IEnvelope
invalEnv,
esriEngineSketchOperationType
opType,
object
Data);ConstantValueesriEngineSketchOperationGeneral0esriEngineSketchOperationVertexAdded1esriEngineSketchOperationVertexDeleted2esriEngineSketchOperationVertexMoved3privatevoidEngineSketchOperation()
{IEngineSketchOperationsketchOp=newEngineSketchOperationClass();
IEngineEditorengineEditor=newEngineEditorClass();
IEngineEditSketcheditSketch=(IEngineEditSketch)engineEditor;
IEnvelopeinvalidateEnv=((IClone)
editSketch.Geometry.Envelope).Clone()asIEnvelope;
sketchOp.Start(engineEditor);
sketchOp.SetMenuString("DeleteVertex");
IPointCollectionpointCol=(IPointCollection)editSketch.Geometry;
IClonevertexToRemove=(IClone)
pointCol.get_Point(pointCol.PointCount-1);vertexToRemove.Clone();pointCol.RemovePoints(pointCol.PointCount-1,1);editSketch.Geometry=(IGeometry)pointCol;editSketch.RefreshSketch();
sketchOp.Finish(invalidateEnv,esriEngineSketchOperationType.esriEngineSketchOperationVertexDeleted,vertexToRemoveasSystem.Object);
}对于单个绘制操作,使用IEngineSketchOperation.Undo和Redo来实现撤销和重做;IEngineSketchOperation.Undo(derivedfromIOperationStack.Undo)IEngineSketchOperation.Redo(derivedfromIOperationStack.Redo)对于多个绘制操作,则需要先使用IToolbarControl2.OperationStack访问操作栈,然后再使用IOperationStack.Undo或IOperationStack.Redo来实现撤销和重做。绘制操作的事件:
IEngineEditEvents.OnVertexAddedIEngineEditEvents.OnVertexDeletedIEngineEditEvents.OnVertexMovedIEngineEditEvents.OnSketchModified10.1.6使用操作栈由EngineEditor
管理的编辑会话,如果需要undo/redo功能,那么应用程序中必须包含ToolbarControl.IToolbarControl.OperationStack
属性提供了对操作栈的访问。IOperationStack.Undo和IOperationStack.Redo方法则分别用于撤销和重复操作。将编辑和绘制操作添加至操作栈的步骤:在应用程序中添加ToolbarControl,并设置其伙伴控件;实例化ControlsOperationStack
,并将其与ToolbarControl相关联;
连接EngineEditor到ToolbarControl,使得操作栈包含编辑与绘制操作;可以有2种方式实现该功能:将一编辑命令添加到ToolbarControl上;在Form_Load事件中,通过编程连接EngineEditor与ToolbarControl启动编辑会话,并设置IEngineEditor.EnableUndoRedo为true,使编辑会话具有undo/redo功能。2:IOperationStackoperationStack=newControlsOperationStackClass();axToolbarControl1.OperationStack=operationStack;axToolbarControl2.OperationStack=operationStack;3:(a)直接将编辑命令添加到ToolbarControl上(b)连接EngineEditor与ToolbarControlobjecttbr=(object)axToolbarControl1.Object;IExtensionengineEditorExt=m_engineEditorasIExtension;engineEditorExt.Startup(reftbr);调用IEngineEditor.StopOperation方法后编辑操作便被加入到操作栈中,而调用IEngineSketchOperation.Finish方法后绘制操作便被加入到操作栈中。撤销和重做并不会将操作从操作栈中移除,只是将一指针在栈中上下移动。IOperationStackoperationStack=m_ToolbarControl.OperationStack;//Dothefollowingtoundothepreviousoperationonthestack.operationStack.Undo();//Dothefollowingtoredothenextoperationonthestack.operationStack.Redo();10.1.7使用捕捉环境捕捉有助于精确定位要素及编辑绘制的顶点。ArcGIS提供了两种类型捕捉环境:
ArcGISsnappingenvironment(NewinArcGIS10):为捕捉提供了最通用框架,对ArcGIS桌面和ArcGIS
Engine都可用,并使用相同的组件。Editingsnappingenvironment:提供了更精细的捕捉,但只在编辑会话中可用,且对ArcGIS桌面和ArcGIS
Engine使用不同的组件和接口(ISnapEnvironmentforDesktopandIEngineSnapEnvironmentforEngine)。两种捕捉环境的比较ArcGISsnappingenvironmentEditingsnappingenvironmentDesktopsupportYesYesEnginesupportYesYesConfigurationofsnappingagentsYesYesAvailableoutsideaneditsessionYesNoRequiresmanagementofcacheNoYesRespectsdefinitionqueriesonlayersYesNoSupportscustomizationofsnaptipsYesNoSupportsfilteringofindividuallayersYesYesSupportscustomsnappingtypesNoYesAccesstosnapresultviatheapplicationprogramminginterface(API)YesNoArcGISsnappingenvironment(NewinArcGIS10)ArcGIS捕捉环境可用于所有的自定义工具,而不仅仅限于编辑器中的工具。在ArcMap和ArcGISEngine中,ArcGIS捕捉环境是作为应用程序扩展来访问的。ISnappingEnvironment
是ArcGIS捕捉环境的主要接口,这个接口
用于控制捕捉是否激活、使用哪些类型的捕捉及设置捕捉容差、定义捕捉符号。
ArcGIS捕捉环境还提供了IPointSnapper、ISnappingResult
和ISnappingFeedback
接口。ISnappingEnvironment
IPointSnapperISnappingFeedbackISnappingResult从ArcMap中访问ArcGIS捕捉环境在工具类中声明以下变量:IPointm_CurrentMouseCoords;ISnappingEnvironmentm_SnappingEnv;IPointSnapperm_Snapper;ISnappingFeedback
m_SnappingFeedback;在工具类中的OnClick方法中插入以下代码:m_SnappingEnv=m_application.FindExtensionByName(“ESRISnapping”)
as
ISnappingEnvironment;m_Snapper=m_SnappingEnv.PointSnapper;m_SnappingFeedback=newSnappingFeedbackClass();m_SnappingFeedback.Initialize
(hook,m_SnappingEnv,true);publicvoidInitialize(objectHook,ISnappingEnvironmentsnapEnv,boolautoErase);从ArcGISEngine中访问ArcGIS捕捉环境在工具类中声明以下变量:IHookHelper
m_hookHelper;IHookHelper2
m_hookHelper2;ISnappingEnvironmentm_SnappingEnv;IPointm_CurrentMouseCoords;IPointSnapperm_Snapper;ISnappingFeedback
m_SnappingFeedback;OnCreatem_hookHelper=newHookHelperClass();
m_hookHelper.Hook=hook;m_hookHelper2=m_hookHelperasIHookHelper2;OnClick
IExtensionManagerextensionManager=m_hookHelper2.ExtensionManager;UIDguid=newUIDClass();guid.Value="{E07B4C52-C894-4558-B8D4-D4050018D1DA}";
IExtensionextension=extensionManager.FindExtension(guid);
m_SnappingEnv
=
extensionasISnappingEnvironment;m_Snapper=m_SnappingEnv.PointSnapper;m_SnappingFeedback=newSnappingFeedbackClass();m_SnappingFeedback.Initialize
(hook,m_SnappingEnv,true);esriSnappingTypeConstantValueDescriptionesriSnappingTypeNone0Nosnap.esriSnappingTypePoint1Snaptopoint.esriSnappingTypeEndpoint2Snaptoendpoint.esriSnappingTypeVertex4Snaptovertex.esriSnappingTypeEdge8Snaptoedge.esriSnappingTypeMidpoint16Snaptomidpoint.esriSnappingTypeIntersection32Intersectionsnapping.esriSnappingTypeTangent64Tangentsnapping.X
X
X
X
X
X
X1
1
1
1
1
1
164
32
16
8
4
2
1
配置捕捉环境//SpecifycombinationofesriSnappingTypeenumerations.m_SnappingEnvironment.SnappingType=(esriSnappingType)((int)esriSnappingType.esriSnappingTypeEdge+(int)esriSnappingType.esriSnappingTypeEndpoint);//Specifybitwisecombinationforedgeandendpointsnapping.m_SnappingEnvironment.SnappingType=(esriSnappingType)63;捕捉的优先级按下列顺序计算捕捉类型:esriSnappingTypePointesriSnappingTypeIntersectionesriSnappingTypeEndpointesriSnappingTypeVertexesriSnappingTypeMidpointesriSnappingTypeTangentesriSnappingTypeEdgeSnappingTypeisanapplication-levelsetting.在自定义的工具中使用捕捉功能如果定制的工具使用编辑器绘制工具(theeditorSketchtool)作为输入的话,因为绘制工具已经内置了捕捉功能,所以没有必要在定制的工具添加捕捉功能。对于其他情况,如在定制工具中使用屏幕反馈对象产生的几何作为工具的输入,则需要按照下列步骤在定制工具中添加捕捉功能:(CreateRectangleTool)(1)在工具的OnClick
事件中,获得对捕捉扩展的引用(参照上面的相关内容),并获得对ISnappingEnvironment
和IPointSnapper的引用;必要的时候使用SnappingFeedback的Initialize方法初始化捕捉环境;(2)在工具的OnMouseMove事件中,IPointSnapper.Snap方法捕捉鼠标的当前位置;如果返回SnapResult,则调用Update方法更新鼠标位置;publicoverridevoidOnMouseMove(intButton,intShift,intX,intY)
{m_CurrentMouseCoords=m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);ISnappingResultsnapResult=m_Snapper.Snap(m_CurrentMouseCoords);m_SnappingFeedback.Update(snapResult,0);if(snapResult!=null)m_CurrentMouseCoords=snapResult.Location;if(pEnvelopeFeedback!=null)pEnvelopeFeedback.MoveTo(m_CurrentMouseCoords);
}(3)在工具的Refresh方法中,刷新捕捉反馈。publicoverridevoidRefresh(inthDC)
{
//Refreshthepreviouslocationofthesnaptip.if(m_SnappingFeedback!=null)
m_SnappingFeedback.Refresh(hDC);
}EditingsnappingenvironmentinArcGISEngine可以使用ControlsEditingSnappingCommand
或IEngineSnapEnvironment
接口来访问捕捉设置.通过实现IEngineSnapAgent
接口来创建定制的捕捉设置。ArcGISEngine的编辑捕捉环境(IEngineSnapEnvironment)控制每一个捕捉代理IEngineSnapAgent,捕捉类型(hittype)设置,及捕捉容差.每个捕捉代理的捕捉类型由IEngineFeatureSnapAgent
管理.所有的设置均可以在捕捉设置对话框中修改或确认。publicvoidSnapEnvirSettings
(IEngineEditoreditor)
{IEngineSnapEnvironmentsnapEnvironment=editorasIEngineSnapEnvironment;if(snapEnvironment.SnapAgentCount==0)
{System.Windows.Forms.MessageBox.Show("Youneedtoturnonatleastonesnappingagent!!!");return;
}
doubletolerance=snapEnvironment.SnapTolerance;MessageBox.Show(Convert.ToString(tolerance));snapEnvironment.SnapToleranceUnits=esriEngineSnapToleranceUnits.esriEngineSnapToleranceMapUnits;snapEnvironment.SnapTolerance=15;((IEngineEditProperties2)editor).SnapTips=true;
}privatevoidEditSnap
(IMapControl3mMap)
{IEngineEditorm_engineEditor=newEngineEditorClass();if(m_engineEditor.EditState==esriEngineEditState.esriEngineStateNotEditing)
{
ILayercurrentLayer=mMap.get_Layer(0);if(currentLayerisIFeatureLayer)
{IFeatureLayerfeatureLayer=currentLayerasIFeatureLayer;
IDatasetdataset=featureLayer.FeatureClassasIDataset;
IWorkspaceworkspace=dataset.Workspace;
m_engineEditor.StartEditing
(workspace,mMap.Map);((IEngineEditLayers)
m_engineEditor).SetTargetLayer(
featureLayer,0);
}if(mMap.LayerCount!=0)
{IEngineEditLayerseditLayers=editorasIEngineEditLayers;
IEngineSnapEnvironmentsnapEnvironment=editorasIEngineSnapEnvironment;
IEngineFeatureSnapAgentfeatureSnapAgent=newEngineFeatureSnap();featureSnapAgent.FeatureClass=((IFeatureLayer)
mMap.get_Layer(0)).FeatureClass;featureSnapAgent.HitType=esriGeometryHitPartType.esriGeometryPartVertex|esriGeometryHitPartType.esriGeometryPartBoundary|esriGeometryHitPartType.esriGeometryPartEndpoint;snapEnvironment.AddSnapAgent(featureSnapAgent);
}
}
}EditingsnappingenvironmentinArcMapArcMap中的编辑捕捉环境,主要通过以下接口进行管理和使用:ISnapEnvironment3ISnapAgentIFeatureSnapAgent2ISnapAgentFeedback10.1.8Editevents在一个编辑会话中的事件由IEngineEditEvents接口来管理,如通过监听IEngineEditEvents.OnSketchFinished以在完成编辑绘制后检测编辑绘制是否有效。Eventorder一个编辑操作可以触发IEngineEditEvents中的多个事件.如:当IEngineEditor.StartEditing()或执行
ControlsEditingStartCommand时触发OnStartEditing,OnSelectionChanged,及OnSketchModified事件.当通过IEngineEditor.CurrentTask
或ControlsEditingTaskToolControl改变当前任务时触发OnSketchModified,OnAfterDrawSketch,及OnCurrentTaskChanged事件当IEngineEditor.StopEditing()或执行ControlsEditingStopCommand
时,触发OnTargetLayerChanged和OnStopEditing事件.可以按下列方式使用编辑事件:privateIEngineEditorm_EngineEditor=newEngineEditorClass();privateIEngineEditEvents_Eventm_EngineEditEvents;……m_EngineEditEvents.OnStartEditing+=newIEngineEditEvents_OnStartEditingEventHandler(OnStartEditingMethod);……privatevoidOnStartEditingMethod(){……
}10.1.9
要素查看器ControlsEditingAttributeCommand对话框包含两个部分,左边为地图上选择的要素,右边为左边选定要素的属性。通过实现IEngineObjectInspector接口并把类注册为要素类扩展,可以将默认的要素查看器替换为定制的要素查看器。10.1.10
使用要素模板ArcGIS10编辑环境中提供了创建要素的要素模板。要素模板提供了快速创建要素的途径,因为设置编辑环境的属性及要素的属性都已预定义好了。要素模板与要素图层(FeatureLayer)相关联,且作为图层的扩展存储在图层中。Creatingfeaturetemplates启动编辑会话时,如果要素图层尚未有要素模板,ArcMap编辑器会为每个要素图层自动创建要素模板。使用IEditTemplate
、IEditTemplateFactory接口创建要素模板,并通过IEditor3
管理要素模板。
IEditor3.CurrentTemplate返回当前模板(IEditTemplate)
.要素模板IEditTemplate定义了以下属性:(1)必选:1)名称:要素模板的名称;2)目标图层:新建要素将要保存到的图层(2)可选:1)默认属性值:新建要素默认具有的字段。2)描述:用于描述要素模板的信息。3)标签:用户定义、系统生成的用以描述要素模板的关键字,用分号隔开。4)工具:默认的能按照该要素模板创建要素的工具。IEditTemplateIEditTemplateFactory仅定义了Create方法,用来创建编辑模板。UseIEditor3.AddTemplatestoaddthetemplatetotheeditor.publicIEditTemplateCreate(
string
Name,
ILayer
Layer);privatevoidCreateFeatureTemplate(
IMxDocumentm_doc,IEditor3m_editor)
{//Createasingletemplatefortheselectedlayer.
ILayereditLayer=m_doc.SelectedLayer;
IEditTemplateFactoryeditTemplateFact=newEditTemplateFactoryClass();
IEditTemplatenewEditTemplate=editTemplateFact.Create("Building",editLayer);
//Addthetemplate.
IArraytemplateArray=newArrayClass();templateArray.Add(newEditTemplate);m_editor.AddTemplates(templateArray);
}Accessingfeaturetemplates使用IEditTemplateManager来访问要素模板对象:publicvoidGetEditTemplateManager(ILayerlayer)
{ILayerExtensionslayerExtensions=layerasILayerExtensions;
IEditTemplateManagereditTemplateMgr;for(intj=0;j<layerExtensions.ExtensionCount;j++)
{objectextension=layerExtensions.get_Extension(j);if(extensionisIEditTemplateManager)
{editTemplateMgr=extensionasIEditTemplateManager;
IEditTemplateeditTemplate=editTemplateMgr.get_EditTemplate(0);editTemplate.SetDefaultValue("Name","Venice",true);
}
}
}publicvoidm_editEvents_OnSketchFinished(IEditor3m_editor)
{IEditSketch3m_edSketch=m_editorasIEditSketch3;m_editor.StartOperation();
IPointpoint=m_edSketch.LastPoint;
IEditTemplateeditTemplate=m_editor.CurrentTemplate;
IFeatureLayerfeatLayer=editTemplate.LayerasIFeatureLayer;
IFeatureClassfeatClass=featLayer.Fea
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论