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'.
如果许多Feature要更新,使用Update比单独更新Feature快.
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.
如果你要创建自定义的Features(且在建立/修改/删除时不包含多态行为),你可以通过将CanBypassStoreMethod 属性设为true来实现 IObjectClassInfo接口.
做完这个后,可以导致Geodatabase回避这个Feature用来更新插入cursors的实现
你也可以实现IObjectClassInfo2接口,CanBypassEditSession 返回true,表明这些Features可以在一个edit session外被更新.
//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);
}