Arc: Editing Data - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Arc: Editing Data

Description:

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 ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 17
Provided by: StanO150
Category:
Tags: arc | data | editing

less

Transcript and Presenter's Notes

Title: Arc: Editing Data


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.FileGD
    BWorkspaceFactoryClass()
  • IWorkspace ws wsF.OpenFromFile(geodatabasePath,
    0)
  • Find current (note difficulties with proxy
    classes)
  • IFeatureDatasetProxy ifdp iGeoFeaturelayer.getF
    eatureClass().
  • 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.
  • IFieldEdit fieldEdit 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/esriFieldT
    ype.html

9
Adding a Field
  • Get a FeatureClass from the IFeatureLayer
  • IFeatureClass fClass featurelayer.getFeatureC
    lass()
  • Add the field to the existing fields.
  • IFields fields fClass.getFields()
  • fClass.addField(field)
  • Might want to check the field doesnt 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
  • IFeatureCursor fCursor 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 dont 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 weve 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
  • IPoint point 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 isnt 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.
Write a Comment
User Comments (0)
About PowerShow.com