Arc Editing Data Dr Andy Evans Editing Data

  • Slides: 16
Download presentation
Arc: Editing Data Dr Andy Evans

Arc: Editing Data Dr Andy Evans

Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a

Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a value.

Editing sessions Although some cursors can be used directly in some circumstances to edit

Editing sessions Although some cursors can be used directly in some circumstances to edit data, it is usually worth opening an editing session programmatically. To do this, we need the workspace.

Workspaces Open a workspace (casts/try-catches removed throughout): IWorkspace. Factory ws. F = new Data.

Workspaces Open a workspace (casts/try-catches removed throughout): IWorkspace. Factory ws. F = new Data. Sources. GDB. File. GDBWorkspace. Factory. Class(); IWorkspace ws = ws. F. Open. From. File(geodatabase. Path, 0); Find current (note difficulties with proxy classes): IFeature. Dataset. Proxy ifdp = i. Geo. Featurelayer. get. Feature. Class(). get. Feature. Dataset(); IWorkspace. Proxy iwp = ifdp. get. Workspace(); IWorkspace. Factory wf = iwp. get. Workspace. Factory(); IWorkspace ws = wf. open. From. File (iwp. get. Path. Name(), 0);

Workspaces Make one: IWorkspace. Name wsn = workspace. Factory. create ("c: temp", "temp. GDB",

Workspaces Make one: IWorkspace. Name wsn = workspace. Factory. create ("c: temp", "temp. GDB", null, 0); IName name = wsn; IWorkspace i. Workspace = name. open(); Once we have an i. Workspace, cast to IWorkspace. Edit : IWorkspace. Edit iwe = (IWorkspace. Edit) i. Workspace;

Editing sessions iwe. start. Editing(true); iwe. start. Edit. Operation(); iwe. stop. Editing(true); Opens a

Editing sessions iwe. start. Editing(true); iwe. start. Edit. Operation(); iwe. stop. Editing(true); Opens a session Starts a group of edits Ends a group of edits Closes session You can do multiple edit operations within a session. They are only needed for operations on features that are part of a Topology or Geometric Network, but are good practice.

Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a

Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a field. Adding a field: First make a new Field. Then set it up. Then add it.

Making a field/column Note rare making of a new object Note that the IField

Making a field/column Note rare making of a new object Note that the IField label is used to make the object, but we need an IField. Edit view on it to edit things like the name. IField field = new Field(); IField. Edit field. Edit = field; field. Edit. set. Name("Population"); field. Edit. set. Type (esri. Field. Type. Integer); http: //help. arcgis. com/en/sdk/10. 0/Java_AO_ADF/api/arco bjects/com/esri/arcgis/geodatabase/esri. Field. Type. html

Adding a Field Get a Feature. Class from the IFeature. Layer IFeature. Class f.

Adding a Field Get a Feature. Class from the IFeature. Layer IFeature. Class f. Class = featurelayer. get. Feature. Class(); Add the field to the existing fields. IFields fields = f. Class. get. Fields(); f. Class. add. Field(field); Might want to check the field doesn’t exist with f. Class. find. Field("column. Name") first (returns -1 when none found).

Editing data Use a cursor to find the features to edit. Get a feature.

Editing data Use a cursor to find the features to edit. Get a feature. Edit its value for a specific column. Tell the cursor to store the changes back into the original database. Release the cursor resources.

Editing Data is set using a Feature. Cursor to get the feature: IFeature. Cursor

Editing Data is set using a Feature. Cursor to get the feature: IFeature. Cursor f. Cursor = null; Three types: f. Cursor = f. Class. IFeature. Class_update(null, false) f. Cursor = f. Class. IFeature. Class_insert(false) f. Cursor = f. Class. search(null, false) IFeature feature = p. FCursor. next. Feature(); Cursors also have methods for adding and deleting rows.

Cursors “Recycling” cursors can reuse resources allocated to a row. We don’t want this,

Cursors “Recycling” cursors can reuse resources allocated to a row. We don’t want this, as these temporarily store changes we want. Therefore, we need to use non-recycling cursors: f. Cursor = f. Class. IFeature. Class_insert(false) It also means we must be extra-careful to release resources at the end of editing. To do this we use the ESRI Cleaner class after we’ve finished with the cursor/editing: Cleaner. release(cursor);

Change the value feature. set. Value(column. Index, Object); To change a spatial location you

Change the value feature. set. Value(column. Index, Object); To change a spatial location you set the shape column “SHAPE”: IPoint point = new Point(); point. set. X(300000. 0); point. set. Y(799000. 0); feature. set. Value(shape. Column. Index, point); Or, better: feature. set. Shape. By. Ref(point);

Shapes Implement com. esri. arcgis. geometry IGeometry. Include: Line / Polyline Polygon / Multi.

Shapes Implement com. esri. arcgis. geometry IGeometry. Include: Line / Polyline Polygon / Multi. Patch Point / Multipoint

Fix the value For an Update/Insert Cursor: f. Cursor. update. Feature(feature); For a Search

Fix the value For an Update/Insert Cursor: f. Cursor. update. Feature(feature); For a Search Cursor: feature. store(); Note the different objects the methods are in. Note also that because IFeatures actually inherit from IRow, similar things can be done to table rows. See IFeature. Class docs for info. Note that under some circumstances editing using Update and Insert cursors is possible outside of an editing session, but isn’t advised.

Summary: Editing Open an edit session. Open an edit operation. Get a cursor of

Summary: Editing Open an edit session. Open an edit operation. Get a cursor of features to edit. Edit the features. Tell the cursor to fix the changes. Free up cursor resources. Close the edit operation. Close the edit session.