Editing in a custom application


Purpose
This sample demonstrates how to hide the complexity of editing in an ArcGIS Engine application by presenting a simple editing interface to users. It also shows how to impose business rules on the editing process by listening to ArcGIS Engine edit events. Applications that allow users to edit data often attempt to simplify the editing process and maintain data integrity through business rules. This sample demonstrates how to achieve this in an ArcGIS Engine application in the following ways:
  • Presenting a simple user interface (UI) for editing. Users can only edit the Highways layer and do not have to understand what a target layer is or how to select an appropriate edit task.
  • Using out-of-the-box tools and edit tasks. User can create highways and modify (move, insert, and delete vertices) and reshape the highways.
  • Imposing business rules on the editing process. For demonstration purposes, a hypothetical rule has been created that states that highways cannot intersect lakes.
The application listens to the IEngineEditEvents.OnSketchModified event to check whether an edit is valid. A spatial query is performed in the IsHighwaysEditValid function to determine whether the highway feature being edited intersects the Lakes layer. If the function returns false, the edit is rolled back by calling the IOperationStack.Undo method. The user is notified with an Invalid Edit warning.

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. Click the Start button to start an edit session. The Create, Modify, and Reshape buttons are enabled, and the Start button is replaced by the Finish button.
  3. Click the Create button to create a new feature. The Sketch tool is activated.
  4. Sketch a highway feature on the map. If the feature crosses a lake, you are notified that the edit is invalid.
  5. Double-click to finish the sketch.
  6. Click the Modify button to modify a feature. The Edit tool is activated. If you have a highway feature selected, the Insert and Delete Vertex commands are also enabled.
  7. Use the Edit tool to select a highway feature to edit. The feature's vertices are displayed.
  8. Zoom in on the feature, and use the Insert or Delete commands on any of the feature's vertices. You are notified if your modifications cause a highway feature to cross a lake.
  9. Click the Reshape button to reshape a highway feature. The Edit tool is activated. If you have a highway feature selected, the Sketch tool is also enabled.
  10. Use the Edit tool to select a highway feature to edit. The Sketch tool is now enabled if it wasn't in the previous step.
  11. Use the Sketch tool to digitize a line that crosses the selected highway feature in at least two places. You are notified if your modifications cause a highway feature to cross a lake.
  12. Click Finish to stop the editing and save your edits if desired.


Download the files for Java
editing/CustomEditingApplication.java Entry point for the sample. It initializes the interop, sets up the UI, and ensures licensing is valid.
editing/TOCToolbarPanel.java Contains the UI code to place the TOC control and the Toolbar control side by side.
editing/EditingPanel.java Contains the UI code to create two Toolbar controls and four JButtons to initiate different editing operations. Events fired from the JButtons are handled by the EditingPanelActionListener class.
editing/EditingPanelActionListener.java Contains the code to initiate the different editing operations and to populate the toolbars with tools depending on the editing operation. It also contains the business logic to determine if the edit being made is invalid and subsequently undoes the last edit.
editing/CustomVertexTools.java Contains the code to implement a sub-typed command. A sub-typed 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/ReshapePolylineEditTask.java Contains the code to implement a custom edit task and responds to events in the editing framework.




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView