1 / 16

Arc: Editing Data

Arc: Editing Data. Dr Andy Evans. 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 data, it is usually worth opening an editing session programmatically.

maylin
Télécharger la présentation

Arc: Editing Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arc: Editing Data Dr Andy Evans

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

  3. 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.

  4. Workspaces Open a workspace (casts/try-catches removed throughout): IWorkspaceFactory wsF = new DataSourcesGDB.FileGDBWorkspaceFactoryClass(); IWorkspace ws = wsF.OpenFromFile(geodatabasePath, 0); Find current (note difficulties with proxy classes): IFeatureDatasetProxy ifdp = iGeoFeaturelayer.getFeatureClass(). getFeatureDataset(); IWorkspaceProxy iwp = ifdp.getWorkspace(); IWorkspaceFactory wf = iwp.getWorkspaceFactory(); IWorkspace ws = wf.openFromFile (iwp.getPathName(), 0);

  5. Workspaces Make one: IWorkspaceName wsn = workspaceFactory.create ("c:\temp","tempGDB",null,0); IName name = wsn; IWorkspace iWorkspace = name.open(); Once we have an iWorkspace, cast to IWorkspaceEdit : IWorkspaceEdit iwe = (IWorkspaceEdit) iWorkspace;

  6. Editing sessions iwe.startEditing(true); Opens a session iwe.startEditOperation(); Starts a group of edits iwe.stopEditOperation(); Ends a group of edits iwe.stopEditing(true); 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.

  7. 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.

  8. Making a field/column IField field = new Field(); Note rare making of a new object Note that the IField label is used to make the object, but we need an IFieldEdit view on it to edit things like the name. IFieldEditfieldEdit = field; fieldEdit.setName("Population"); fieldEdit.setType (esriFieldType.esriFieldTypeInteger); http://help.arcgis.com/en/sdk/10.0/Java_AO_ADF/api/arcobjects/com/esri/arcgis/geodatabase/esriFieldType.html

  9. Adding a Field Get a FeatureClass from the IFeatureLayer IFeatureClass fClass = featurelayer.getFeatureClass(); Add the field to the existing fields. IFields fields = fClass.getFields(); fClass.addField(field); Might want to check the field doesn’t exist with fClass.findField("columnName") first (returns -1 when none found).

  10. 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.

  11. Editing Data Data is set using a FeatureCursor to get the feature: IFeatureCursorfCursor = null; Three types: fCursor = fClass.IFeatureClass_update(null,false) fCursor = fClass.IFeatureClass_insert(false) fCursor = fClass.search(null, false) IFeature feature = pFCursor.nextFeature(); Cursors also have methods for adding and deleting rows.

  12. 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: fCursor = fClass.IFeatureClass_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);

  13. Change the value feature.setValue(columnIndex, Object); To change a spatial location you set the shape: IPointpoint = new Point(); point.setX(300000.0); point.setY(799000.0); feature.setValue(shapeColumnIndex,point); Or, better: feature.setShapeByRef(point);

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

  15. Fix the value For an Update/Insert Cursor: fCursor.updateFeature(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 IFeatureClass 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.

  16. 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.

More Related