修改Feature的属性表的值

首先一定要获取Featureclass,利用Featureclass获取IWorkspace和IWorkspaceEdit:

                IWorkspace workspace = ((IDataset)pFeatureClass).Workspace;
                IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

然后开启编辑状态:

                bool startEdit = workspaceEdit.IsBeingEdited();
                if (!startEdit)
                {
                    workspaceEdit.StartEditing(false);
                }
                workspaceEdit.StartEditOperation();

然后获取IFeatureCursor和IFeature:

                pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);

                //注意这里一定要为false,因为http://forums.arcgis.com/threads/45879-Cannot-call-Store-on-a-recycled-row-while-editing

                //如果为true可能会产生0x80040958的错误
                pFeature = pFeatureCursor.NextFeature();

然后用IFeature.set_Value()方法对Feature进行属性表值的修改:

                 pFeature.set_Value(i, valueToSet);

修改完成,要用IFeature.store()方法保存:

                pFeature.Store();

然后最好将Feature释放掉,再进行接下来的修改:

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
                pFeature = null;
                pFeature = pFeatureCursor.NextFeature();

接下来用IFeatureCursor.Flush():

                pFeatureCursor.Flush();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);

最后停止编辑状态:
                workspaceEdit.StopEditOperation();
                startEdit = workspaceEdit.IsBeingEdited();
                if (!startEdit)
                {
                    workspaceEdit.StopEditing(true);
                }

原文地址:https://www.cnblogs.com/henyihanwobushi/p/2947275.html