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/us_lakes and <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.
- Compile and run the sample.
- Click the launch editor form command (blue square, white E).
- Click Edit on the EditorForm to start editing the Highways layer.
- On the EditorForm, try the Create, Modify, and Reshape tools.
- Perform an action to intersect a lake, for example, digitize a new road through a lake (the application should not allow you to do this).
- Try the undo and redo functionality.
- Click Finish to stop editing (save or discard edits). See the following screen shot:
Additional information
Applications that allow users to edit data often attempt to simplify the editing process and maintain data integrity through business rules. The following shows how this sample achieves this in an ArcGIS Engine application:
- Present 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 have to select an appropriate edit task.
- Use out-of-the-box tools and edit tasks. Users can create highways, modify (move, insert, and delete vertices), and reshape highways.
- Impose business rules on the editing process. For demonstration purposes, a hypothetical rule has been created that states highways cannot intersect lakes.
Presenting a simple UI for editing
The MainForm form provides viewing capabilities for the application and the EditorForm (shown in the previous screen shot) presents a simple UI dedicated to editing the Highways layer.
To start an edit session, click the E command (EditCmd) on the MainForm, then click Edit in the EditorForm. The target layer is set to Highways using the IEngineEditLayers.SetTargetLayer method. Clicking one of the editing buttons (Create, Modify, and Reshape) adds an appropriate ToolbarControl to the flowLayoutPanel1 and sets the edit task using the IEngineEditor.CurrentTask property. Each ToolbarControl contains out-of-the-box editing commands or sample commands.
Buddying controls hosted on separate forms
Buddying the ToolbarControls hosted on the EditorForm with the axMapControl1 on the MainForm has been achieved through the use of the EditHelper class.
- In the MainForm_Load event procedure, the EditHelper.TheMainForm property is set to reference the MainForm. This property can be called without an instance of the EditHelper class as it is marked as static. An internal instance of the EditHelper class is created the first time the property is called (acts like a singleton object).
- In the EditorForm_Load event procedure, a reference to the MainForm is available through the EditHelper.TheMainForm property. The MainForm.MapControl property is then used to return an axMapControl1 reference to the EditorForm.
Imposing business rules on the editing process
The EditorForm listens to the IEngineEditEvents.OnSketchModified event to check whether an edit is valid or invalid. 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—an Invalid Edit warning appears on the EditorForm.
MainForm.cs | The main form for the application. |
EditorForm.cs | The form used to provide editing functionality. |
EditHelper.cs | A helper class that enables communication between the MainForm and the EditorForm. |
EditCmd.cs | The command that launches the EditorForm. |
MainForm.vb | The main form for the application. |
EditorForm.vb | The form used to provide editing functionality. |
EditHelper.vb | A helper class that enables communication between the MainForm and the EditorForm. |
EditCmd.vb | The command that launches the EditorForm. |
Download the files for all languages
See Also:
Sample: Custom reshape polyline edit taskSample: Custom vertex editing commands
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |