IFeatureClass.Update 修改Feature

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外被更新.

[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);
    }

 

 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值