五万项目中,需要进行原始数据和编辑数据的对比检查,本文介绍开发相关功能的一些思考。
1 五万增量更新基本常识
1.1 操作及赋值情况
1.2 正确的情形
- 标记删除要素:
- STACOD=删除,VERS=2020
- 图形属性均不变
- 修改要素
大要素拆分
最大要素:STACOD=修改,VERS=2020,FEAID继承原始【派生修改】
非最大要素:STACOD=增加,VERS=2020,FEAID继承原始【派生增加】
单纯修改:STACOD=修改,VERS=2020,FEAID继承原始
纯新增要素:
STACOD=增加,VERS=2020
FEAID=null
1.3 要检查的错误类型及错误提示
2 代码书写及测试
2.1 三种要素光标
2.1.1 IFeatureClass.Search()
搜索游标,频繁调用Store效率较低;不能使用UpdateFeature()和InsertFeature()方法进行要素更新和插入
//搜索游标 IFeatureCursor srcCursor= featureClass.Search(null, false); IFeature pFeature = srcCursor.NextFeature(); while(pFeature != null) { pFeature.Set_value(pFeature.Fields.FindField("STACOD"), "修改"); pFeature.Store(); pFeature = srcCursor.NextFeature(); }
2.1.2 IFeatureClass.Update()
只能更新数据,必能插入
//更新游标 IFeatureCursor srcCursor= featureClass.Update(null, false); IFeature pFeature = srcCursor.NextFeature(); while(pFeature != null) { pFeature.Set_value(pFeature.Fields.FindField("STACOD"), "修改"); srcCursor.UpdateFeature(pFeature); pFeature = srcCursor.NextFeature(); } srcCursor.Flush();
2.1.3 IFeatureClass.Insert()
只能插入,不能更新
public static void InsertFeaturesUsingCursor(IFeatureClass featureClass, List < IGeometry > geometryList) { using(ComReleaser comReleaser = new ComReleaser()) { // Create a feature buffer. IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); comReleaser.ManageLifetime(featureBuffer); // Create an insert cursor. IFeatureCursor insertCursor = featureClass.Insert(true); comReleaser.ManageLifetime(insertCursor); // All of the features to be created are classified as Primary Highways. int typeFieldIndex = featureClass.FindField("TYPE"); featureBuffer.set_Value(typeFieldIndex, "Primary Highway"); foreach (IGeometry geometry in geometryList) { // Set the feature buffer's shape and insert it. featureBuffer.Shape = geometry; insertCursor.InsertFeature(featureBuffer); } // Flush the buffer to the geodatabase. insertCursor.Flush(); } }
2.2 创建要素的两种主要方式:
- 使用IFeatureClass.CreateFeature 和 IFeature.Store
- 使用IFeatureClass.CreateFeatureBuffer 和 insert cursor
两种方式的区别:
Store()方法
会触发所有对象行为,包括但不限于网络或注释的特定行为、要素参与的拓扑运算;也包括事件,如IObjectClassEvents 接口。
Calling IFeature.Store results in all object behavior being triggered. This includes—but is not limited to—behavior specific to network or annotation features and features that participate in a topology, as well as events, such as those from the IObjectClassEvents interface.
Insert cursors
插入光标用于向GDB中批量插入要素,使用插入光标和要素缓冲,提供了比简单的加载-创建要素-存储更快的性能
一个要注意的问题是使用 IFeatureCursor.InsertFeature 方法并不能确保复杂行为和事件被触发。
Insert cursors are used to bulk insert features in the geodatabase. Using an insert cursor and a feature buffer offers significantly faster performance for simple data loading and creation than creating features and storing them. The one catch is that when using the IFeatureCursor.InsertFeature method, complex behavior and the triggering of events is not guaranteed.
IObjectClassInfo和IWorkspaceEditControl接口可用于通过insert cursors强制调用IFeature.Store,但这否定了它们提供的任何性能优势。【The IObjectClassInfo and IWorkspaceEditControl interfaces can be used to enforce the calling of IFeature.Store by insert cursors, but this negates any performance advantages they offer.】