In this section:
Example Code Click here
Description This project provides a custom edit task, an edit task that can be used to create new point features at the end of a polyline edit sketch using any of the available sketch tools, without having to first construct a temporary geometry to help locate the new point feature. The task will appear in the Tasks combo box on the Editor toolbar.
Design Coclass ConstructPointTask is a subtype of the EditTask abstract class and also sinks the IEditEvents interface.
License required ArcEditor or above
Libraries Carto, Display, Editor, Geodatabase, and Geometry
Languages Visual Basic
Categories ESRI Edit Tasks
Interfaces IEditTask and IEditEvents
How to use
A new point feature will be added to your target layer at the last vertex of the edit sketch.
You want to be able to create new point features at precise locations relative to existing features. For example, you want to add a new Pole feature 145 feet from an existing pole, at a bearing of 40 degrees. Using the existing tool, you could create a temporary line feature starting at the existing pole and ending at the required location by using the Direction and Length command; then you could create the new Pole point feature at the end of the temporary line and delete the line.
The best solution for this scenario is to create a custom edit task that creates new point features at the end of a polyline edit sketch. When a polyline edit sketch has been completed, a new point feature will be added to the target layer at the location of the end of the edit sketch, and the remaining portion of the edit sketch geometry will be deleted.
A different way to solve this problem may be to create a custom edit tool. However, if you create an edit task, your code can take advantage of all the sketch tools, which already exist to locate the point, lending more flexibility to your solution.
This example demonstrates how to create a custom edit task to create point features at the end of an edit sketch, without needing to create a temporary feature as an interim step.
By reviewing the Editor object model diagram, you will see the EditTask abstract class,
which implements the IEditTask interface. As mentioned in
About Edit Tasks, most edit tasks also listen to
events from the Editor.
To meet the requirements described above, you will create a subtype of the EditTask abstract class by implementing IEditTask, and you will also sink the IEditEvents interface.
The first member of IEditTask to be called will be Activate, when the task is selected in the editor toolbar. Store a reference to the Editor object, which is passed in to this member; you will need to use the IEditSketch and IEditLayer interfaces of this member.
Privatem_pEditorAsesriEditor.IEditorPrivatem_pEditSketchAsesriEditor.IEditSketchPrivatem_pEditLayersAsesriEditor.IEditLayerPrivate SubIEditTask_Activate(ByValEditorAsesriEditor.IEditor,ByValoldTaskAsesriEditor.IEditTask)Setm_pEditor = EditorSetm_pEditSketch = m_pEditor'QISetm_pEditLayers = m_pEditor'QIEnd Sub
When the user finishes an edit sketch with the ConstructPointTask as the active task, the OnFinishSketch method will be called. In this method, you need to retrieve the final point of the sketch geometry and create a new feature. The new feature also needs any default values set, and finally, the map display should be refreshed so the new feature and new selection appear correctly.
Private SubIEditTask_OnFinishSketch()DimbInOperationAs Booleanm_pEditor.StartOperation bInOperation =True
DimpPointAsesriGeometry.IPointSetpPoint = m_pEditSketch.LastPoint
DimpFeatureAsesriGeodatabase.IFeatureSetpFeature = m_pEditLayers.CurrentLayer.FeatureClass.CreateFeatureDimpRowSubTypesAsesriGeodatabase.IRowSubtypesDimpSubtypesAsesriGeodatabase.ISubtypesIf TypeOfm_pEditLayers.CurrentLayer.FeatureClassIsesriGeodatabase.ISubtypesThen SetpSubtypes = m_pEditLayers.CurrentLayer.FeatureClassSetpRowSubTypes = pFeatureIfpSubtypes.HasSubtypeThenpRowSubTypes.SubtypeCode = m_pEditLayers.CurrentSubtypeEnd IfpRowSubTypes.InitDefaultValuesEnd If
SetpFeature.Shape = pPoint pFeature.Store m_pEditor.StopOperation "Add Point" bInOperation =False
DimpInvalidAreaAsesriGeodatabase.IInvalidAreaSetpInvalidArea =NewesriCarto.InvalidAreaSetpInvalidArea.Display = m_pEditor.Display pInvalidArea.Add pFeature pInvalidArea.Invalidate esriAllScreenCaches
DimpActiveViewAsesriCarto.IActiveViewSetpActiveView = m_pEditor.Map pActiveView.PartialRefresh esriViewGeoSelection,Nothing,Nothingm_pEditor.Map.ClearSelection'Clear the selectionm_pEditor.Map.SelectFeature m_pEditLayers.CurrentLayer, pFeature pActiveView.PartialRefresh esriViewGeoSelection,Nothing,Nothing
Private SubIEditTask_OnFinishSketch()On Error GoToErrorHandler: ...Exit Sub' Exit sub to avoid error handlerErrorHandler:IfbInOperationThenm_pEditor.AbortOperation MsgBox "Failed to construct new point at end of sketch."End Sub
From IEditTask::Name return the string that you would like to appear in the edit tasks combo box to identify the task.
Private Property GetIEditTask_Name()As StringIEditTask_Name = "Create Point at End of Sketch"EndPropert
Because this edit task deals strictly with creating new point features, the task should disable the sketch tools whenever the target layer is set to something other than a point feature layer. To do this, you can listen to the OnCurrentLayerChanged event of the IEditEvents interface.
Private WithEventsEditorEventsAsesriEditor.Editor
Private SubIEditTask_Activate(ByValEditorAsesriEditor.IEditor,ByValoldTaskAsesriEditor.IEditTask)Setm_pEditor = EditorSetm_pEditSketch = m_pEditor' QISetm_pEditLayers = m_pEditor' QISetEditorEvents = m_pEditor' Call OnCurrentLayerChanged to see if sketch tools should be active or notEditorEvents_OnCurrentLayerChangedEnd Sub
Private SubEditorEvents_OnCurrentLayerChanged()' Exit if there is no target (current) layerIfm_pEditLayers.CurrentLayerIs Nothing Then Exit SubIf Notm_pEditLayers.CurrentLayer.FeatureClass.ShapeType = esriGeometryPointThenm_pEditSketch.GeometryType = esriGeometryNullElsem_pEditSketch.GeometryType = esriGeometryPolylineEnd If End Sub
Private SubIEditTask_Deactivate()SetEditorEvents =Nothing End Sub
Now you can compile the ConstructPointTask project and use it in an ArcMap edit session. Below you can see the task being used to create a feature in conjunction with the Distance and Direction.
Go to example code
See Also Extending the Editing Framework and About Edit Tasks.