Custom vertex editing commands


Purpose
This sample provides four tools to insert or delete vertices from an edit sketch and shows the following approaches.
  • Using fine grained ArcObjects
  • Using containment to call out-of-the-box commands
It also shows how to create sketch operations. All the tools can be used in conjunction with the out-of-the-box ArcGIS Engine editing commands. The sample assumes previous experience in creating custom tools and commands.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample.

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/USAMajorHighways/usa_major_highways.
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Start editing.
  2. Zoom in on a polyline or polygon feature.
  3. Select a feature with the edit tool.
  4. Try out the vertex tools. To delete a vertex, select one of the Delete Vertex tools and click an existing vertex. To insert a vertex, select one of the Insert Vertex tools and click a selected feature.
  5. Right-click and finish the sketch.
  6. Stop editing and save edits to persist changes.

Additional information

The CustomVertexCommands class and the UsingOutOfBoxVertexCommands class each contain the following tools for vertex management:
  • InsertVertex
  • DeleteVertex
The InsertVertex tool creates a vertex at the clicked location while DeleteVertex deletes the closest vertex. Both classes have the following in common:
  • The classes inherit from the BaseCommand class but implement the ICommandSubType interface; therefore, each contains two tools.
  • The overridden Enabled property on the BaseCommand class determines when the tools become enabled. The following three conditions must be met:
    • There must be an active edit session
    • Only one feature can be selected
    • It must have a polygon or polyline geometry type
  • All tools manipulate the sketch geometry in a sketch operation.
The CustomVertexCommands class uses fine grained ArcObjects to perform the vertex operations. The OnMouseUp event is used to transform the clicked location from screen coordinates to map coordinates using the IDisplayTransformation.ToMapPoint method. 
The IHitTest.HitTest method is then used on the edit sketch geometry to identify the part of the geometry closest to the click location. A search tolerance is used to determine whether the mouse click is too far from the selected feature to be valid. InsertVertex identifies the segment index of the nearest boundary, which is then used with the IPointCollection.AddPoint method to create a vertex. DeleteVertex identifies the index of the nearest vertex, then deletes it by calling IPointCollection.DeletePoints. 
The UsingOutOfBoxVertexCommands class contains the following out-of-the-box ControlsCommands:
  • ControlsEditingSketchVertexInsertCommand 
  • ControlsEditingSketchVertexDeleteCommand
The location of the vertex operation is set by calling IEditSketch.SetEditLocation. The commands are instantiated by using System.Activator.CreateInstance, initialized with OnCreate by passing in the hook, and executed with OnClick.
The approach taken in the CustomVertexCommands class provides greater flexibility programmatically, whereas the UsingOutOfBoxVertexCommands class is more concise with less code to maintain.


Commands/CustomVertexCommands.cs Class file.
Commands/UsingOutOfBoxVertexCommands.cs Class file.
Commands/VertexCommandsMenu.cs Class file.
Application/EditingForm.cs Form file.
Download the C# files
Commands/CustomVertexCommands.vb Class file.
Commands/UsingOutOfBoxVertexCommands.vb Class file.
Commands/VertexCommandsMenu.vb Class file.
Application/EditingForm.vb Form file.
Download the VB.NET files

Download the files for all languages

See Also:

EngineEditorClass




Additional Requirements
  • Active edit session.

Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced