||
首先一定要获取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/archive/2013/03/07/2947275.html
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-25 23:16
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社