linqy的个人博客分享 http://blog.sciencenet.cn/u/linqy

博文

[转载]修改Feature的属性表的值

已有 2763 次阅读 2019-3-8 10:39 |系统分类:科研笔记|文章来源:转载

首先一定要获取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 



https://blog.sciencenet.cn/blog-3134052-1166379.html

上一篇:C# combox绑定数据的问题
下一篇:ArcGIS中我国常用的坐标系统WKID列表
收藏 IP: 221.214.6.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-25 23:16

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部