基于C#的ArcEngine二次开发36: 在地理数据库中创建要素类的接口及方法分析(上)

简介: 基于C#的ArcEngine二次开发36: 在地理数据库中创建要素类的接口及方法分析

五万项目中,需要进行原始数据和编辑数据的对比检查,本文介绍开发相关功能的一些思考。

1 五万增量更新基本常识

1.1 操作及赋值情况

image.png

1.2 正确的情形

  • 标记删除要素:
  • STACOD=删除,VERS=2020
  • 图形属性均不变
  • 修改要素

大要素拆分

最大要素:STACOD=修改,VERS=2020,FEAID继承原始【派生修改】

非最大要素:STACOD=增加,VERS=2020,FEAID继承原始【派生增加】

单纯修改:STACOD=修改,VERS=2020,FEAID继承原始

纯新增要素:

STACOD=增加,VERS=2020

FEAID=null

1.3 要检查的错误类型及错误提示

image.png


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 创建要素的两种主要方式:

两种方式的区别:


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.】


相关文章
|
SQL NoSQL C#
基于C#的ArcEngine二次开发32:属性sql查询语句与IMap,ILayer,IFeatureLayer,IFeatureClass关系
基于C#的ArcEngine二次开发32:属性sql查询语句与IMap,ILayer,IFeatureLayer,IFeatureClass关系
基于C#的ArcEngine二次开发32:属性sql查询语句与IMap,ILayer,IFeatureLayer,IFeatureClass关系
基于C#的ArcEngine二次开发35:缓冲区分析
基于C#的ArcEngine二次开发35:缓冲区分析
基于C#的ArcEngine二次开发35:缓冲区分析
基于C#的ArcEngine二次开发42:空间分析接口及分析(ITopologicalOperator / IRelationalOperator / IProximityOperator)(二)
基于C#的ArcEngine二次开发42:空间分析接口及分析(ITopologicalOperator / IRelationalOperator / IProximityOperator)
基于C#的ArcEngine二次开发42:空间分析接口及分析(ITopologicalOperator / IRelationalOperator / IProximityOperator)(二)
|
Android开发
Android Stadio Build 窗口字符串乱码问题
在使用Android Studio过程中,如果遇到Build窗口字符串乱码问题,可以通过编辑`studio.vmoptions`文件添加`-Dfile.encoding=UTF-8`配置并重启Android Studio来解决。
964 2
Android Stadio Build 窗口字符串乱码问题
|
关系型数据库 MySQL C#
Unable to connect to any of the specified MySQL hosts.
c#连接Mysql数据建立连接时提示:Unable to connect to any of the specified MySQL hosts. 出现此错误的原因是Server(数据库服务器IP地址填写错误) 当Server配置值是“(local)”或者是"(localhost)"时都会产生...
3727 0
|
存储 Python
【Python 基础】解释reduce函数的工作原理
【5月更文挑战第6天】【Python 基础】解释reduce函数的工作原理
|
存储 NoSQL Unix
基于C#的ArcEngine二次开发50:MDB创建新要素类及“无当前记录”异常处理
基于C#的ArcEngine二次开发50:MDB创建新要素类及“无当前记录”异常处理
基于C#的ArcEngine二次开发50:MDB创建新要素类及“无当前记录”异常处理
|
6月前
|
人工智能 IDE 开发工具
Visual Studio 2026 Enterprise 18.3.0 Offline (2026 年 2 月更新)
Visual Studio 2026 Enterprise 18.3.0 Offline (2026 年 2 月更新) - 适用于 Windows 上 .NET 和 C++ 开发人员的最全面 IDE
668 1
Visual Studio 2026 Enterprise 18.3.0 Offline (2026 年 2 月更新)
|
Web App开发 移动开发 前端开发
多种方法实现Loading(加载)动画效果
当我们ajax提交一个按钮的时候,给那个按钮来个Loading效果会高端很多,体验也会上升个层次。 既能让用户知道正在提交中,也能防止二次提交,好处多多呢。
多种方法实现Loading(加载)动画效果
|
安全 Java 编译器
JDK11 介绍讲解,语法改进,API增强
JDK 11进一步完善了JDK 9引入的模块化系统。模块化系统允许开发人员将代码和依赖项组织成模块,以提高可维护性、安全性和性能。开发人员可以使用`module`关键字定义模块,并使用`requires`和`exports`语句来声明模块之间的依赖关系和对外暴露的API。模块化系统还提供了更细粒度的访问控制,可以限制对模块中的内部API的访问。
675 0

热门文章

最新文章