Custom vertex editing tools


Purpose
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 the 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 two tools for vertex management: InsertVertex and DeleteVertex. 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 the 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 either 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 new vertex. the DeleteVertex tool identifies the index of the nearest vertex, then deletes it by calling the IPointCollection.DeletePoints method.
 
The OutOfBoxVertexTools class contains two out-of-the-box controls commands: ControlsEditingSketchVertexInsertCommand and 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. 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 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, and click an existing vertex. To insert a vertex, select either of the Insert Vertex tools, and click next to or on a selected feature.
  6. Stop the edit session using the Editor menu.


Download the files for Java
editing/EditingApplication.java Entry point for the sample. It initializes the interop, sets up the user interface, and ensures licensing is valid.
editing/CustomVertexTools.java 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/OutOfBoxVertexTools.java 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 Runtime
ArcView
ArcEditor
ArcInfo