ArcObjects Library Reference  (GeoDatabase)    

IFeatureClass.Update Method

Returns a cursor that can be used to update features selected by the specified query.

[Visual Basic 6.0]
Function Update(
    ByVal filter As IQueryFilter, _
    ByVal Recycling As Boolean _
) As IFeatureCursor
[Visual Basic .NET]
Public Function Update ( _
    ByVal filter As IQueryFilter, _
    ByVal Recycling As Boolean _
) As IFeatureCursor
[C#]
public IFeatureCursor Update (
    IQueryFilter filter,
    bool Recycling
);
[Java]
public IFeatureCursor update (
    IQueryFilter filter,
    Boolean Recycling
)
throws
    IOException,
    AutomationException
[C++]
HRESULT Update(
  IQueryFilter* filter,
  VARIANT_BOOL Recycling,
  IFeatureCursor** Cursor
);
[C++]

Parameters

filter [in]

  filter is a parameter of type IQueryFilter

Recycling [in]

  Recycling is a parameter of type VARIANT_BOOL

Cursor [out, retval]

  Cursor is a parameter of type IFeatureCursor

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

Update opens an update cursor on the features specified by an attribute and/or spatial query as specified in an IQueryDef. If a number of features selected by a particular query are to be updated and each feature is to be updated to a separate value then the update cursor is faster than doing an individual feature level update for each feature. The update is performed on the current 'cursor position'.

Update cursors can be used on a custom object, with guaranteed polymorphic behavior. Update cursors can be used either inside or outside of an edit session. If used inside an edit session, the changes are not committed to the base table until the edit session is saved. Network feature classes, Topology feature classes, feature classes that participate in composite relationships or other relationships with messaging and some custom feature classes may only be updated within an edit session. If you attempt to use an update cursor on one of these classes outside of an edit session, it will fail.  In addition, edits to features that participate in a Topology or Geometric Network must be bracketed within an edit operation.

If the insert cursor is used on non-simple features (such as network features), the cursor will revert to using IFeature::Store.

If you are creating custom features that do not have polymorphic behavior on creation, update and deletion you can implement the IObjectClassInfo interface to set the CanBypassStoreMethod property to true. Doing this will cause the Geodatabase to bypass the custom feature implementation for update and insert cursors used with that custom feature class. Also, you can implement the IObjectClassInfo2 interface on the object class extension and return true to CanBypassEditSession method to indicate the those custom features can be updated outside of an edit session.

[C#]

    //The following function uses an update cursor to change the value of a particular
    //field for a set of features in a feature class.
    public void IFeatureClass__Update(IFeatureClass featureClass)
    {
        //cast the spatial filter to the IQueryFilter interface
        IQueryFilter queryFilter = new QueryFilterClass();
        queryFilter.WhereClause = "subtype = 'COM'";
        queryFilter.SubFields = "FID, Type";
       
        //preform the search on the supplied feature class; use a cursor to hold the results
        IFeatureCursor featureCursor = featureClass.Update(queryFilter, false);

        //get the first feature returned
        IFeature feature = featureCursor.NextFeature();

        //get the "Area" field
        IFields fields = featureCursor.Fields;
        int fieldIndex = fields.FindField("Type");

        //loop through all of the features and update the field to its new value
        while (feature != null)
        {
            Console.WriteLine("The old type: {0}", feature.get_Value(fieldIndex));
            feature.set_Value(fieldIndex, "ABC");
            featureCursor.UpdateFeature(feature);
            Console.WriteLine("The new type: {0}", feature.get_Value(fieldIndex));
            feature = featureCursor.NextFeature();
        }

        System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
    }

[Visual Basic 6.0]

The following example uses an update cursor to change the value of a particular field for a set of features in a feature class.

Dim pFeatcls As IFeatureClass
 Dim pFeatLayer As IFeatureLayer
 Dim pDoc As IMxDocument
 Dim pMap As IMap
 
 Set pDoc = ThisDocument
 Set pMap = pDoc.Maps.Item(0)
 Set pFeatLayer = pMap.Layer(0)
 Set pFeatcls = pFeatLayer.FeatureClass
 
 ' +++ create the query filter
 Dim pQueryFilter As IQueryFilter
 Set pQueryFilter = New QueryFilter
 With pQueryFilter
   .WhereClause = "subtype = 'COM'"
   .SubFields = "FID, Type"
 End With
 
 ' +++ get the field we are interested in updating  
 Dim lFld As Long
 Dim pFlds As IFields
 Dim pTable As ITable
 Dim pFeatCur As IFeatureCursor
 Dim pFeat As IFeature
 
 Set pFeatCur = pFeatcls.Update(pQueryFilter, False)
 Set pFlds = pFeatcls.Fields
 lFld = pFlds.FindField("Type")
 
 ' +++ loop through each feature and update
 ' +++ the field to its new value    
 Set pFeat = pFeatCur.NextFeature
 
 While Not pFeat Is Nothing
   Debug.Print "The old type: " & pFeat.Value(lFld)
   pFeat.Value(lFld) = "ABC"
   pFeatCur.UpdateFeature pFeat
   Debug.Print "The new type: " & pFeat.Value(lFld)
   Set pFeat = pFeatCur.NextFeature
 Wend

See Also

IFeatureClass Interface | IFeature Interface | IFeatureCursor Interface

 


Feedback Send feedback on this page