Custom vertex editing tools

This sample provides four tools that insert and delete vertices from features in polygon and polyline layers. Two tools are used in an approach that builds the tools from fine-grained ArcObjects, and two tools are used in an approach that uses containment to call out-of-the-box commands. All tools can be used in conjunction with the out-of-the-box ArcGIS Engine editing commands.
The CustomVertexCommands class and the UsingOutOfBoxVertexCommands class each contain the following two tools for vertex management:
  • InsertVertex—Creates a vertex at a clicked location.
  • DeleteVertex—Deletes the closest vertex.
Both classes have the following in common:
  • The classes inherit from the BaseTool class but implement the ICommandSubType interface so that each class can contain two tools.
  • All tools manipulate sketch geometry in a sketch operation.
  • The overridden Enabled property on the BaseTool class determines when the vertex management tools become enabled. The following conditions must be met:
    • There must be an active edit session.
    • Only one feature can be selected.
    • The selected feature must have a polygon or polyline geometry type.
The CustomVertexTools class uses fine-grained ArcObjects to perform 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 selected feature in the target layer to identify the part of the geometry closest to the mouse click location. A search tolerance is used to determine whether the user-click is too far from the selected feature to be valid. The InsertVertex tool identifies the segment index of the nearest boundary, which is then used with the IPointCollection.AddPoint method to create a vertex. The DeleteVertex tool identifies the index of the nearest vertex, then deletes it by calling the IPointCollection.DeletePoints method.
The OutOfBoxVertexTools class contains the following out-of-the-box controls commands:
  • ControlsEditingSketchVertexInsertCommand
  • ControlsEditingSketchVertexDeleteCommand
The location of the vertex operation is set by calling the IEditSketch.SetEditLocation method. The commands are instantiated using the System.Activator.CreateInstance method, initialized with the OnCreate method by passing in the hook, and executed with the OnClick method.
The approach taken in the CustomVertexTools class provides greater flexibility programmatically. The OutOfBoxVertexTools class is more concise and has less code to maintain.

How to use

See How to use ArcGIS samples for help on running the sample.

  1. Start the sample application. The ushigh.shp shapefile from the sample data is loaded into the Map control.
  2. Start an edit session using the Editor menu on the toolbar. The editing controls on the toolbar are enabled.
  3. Zoom in to an area on the map where you want to reshape a highway feature.
  4. Use the Edit tool to select a feature by clicking the feature. The feature is highlighted in blue, and the custom and out-of-the-box tools in the Vertex Tools menu are enabled.
  5. Use the vertex tools. To delete a vertex, select either of the Delete Vertex tools, then click an existing vertex. To insert a vertex, select either of the Insert Vertex tools, then click next to or on a selected feature.
  6. Stop the edit session using the Editor menu.

If you installed the samples feature, you will find the files associated with this sample in <Your Developer Kit install location>\DeveloperKit10.4\Java\Samples\ArcObjects.

editing/ Entry point for the sample. It initializes the interop, sets up the user interface (UI), and ensures licensing is valid.
editing/ Contains the code to implement a subtyped command. A subtyped command gives the appearance of multiple commands even though it is a single command. The command uses fine-grained ArcObjects to perform vertex editing.
editing/ Contains the code to implement a subtyped command. A subtyped command gives the appearance of multiple commands even though it is a single command. The command delegates to the out-of-the-box commands to perform vertex editing.

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