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


相关文章
|
7天前
|
数据采集 数据可视化 测试技术
C#生成Selenium测试报告:实用方法与技巧
在C#中使用Selenium进行自动化测试时,结合代理IP和ExtentReports能增强测试安全性和报告质量。安装必备工具如Selenium WebDriver、NUnit和ExtentReports。在测试设置中,配置代理(如亿牛云爬虫代理)以隐藏IP,通过ChromeOptions定制UserAgent,并添加Cookie。测试代码示例展示了如何打开网页、执行搜索并生成详细的测试报告。使用ExtentReports可创建可视化测试结果,便于团队分析。
C#生成Selenium测试报告:实用方法与技巧
|
8天前
|
C#
技术经验分享:C#DUID的用法及取得整数的几个方法
技术经验分享:C#DUID的用法及取得整数的几个方法
14 1
|
13天前
|
C#
蓝易云 - C#将异步改成同步方法
注意:虽然这样可以将异步方法转为同步,但在实际开发中,我们通常推荐使用异步方法,因为它可以提高应用程序的响应性和并发性。将异步方法转为同步可能会导致死锁或性能问题。
11 2
|
1天前
|
关系型数据库 MySQL 数据库
生成订单的过程------支付系统21------支付宝支付----统一收单下单并支付页面接口----创建订单,下订单,我们要在我们数据库的订单表中,设置订单,订单表常用数据库设置格式
生成订单的过程------支付系统21------支付宝支付----统一收单下单并支付页面接口----创建订单,下订单,我们要在我们数据库的订单表中,设置订单,订单表常用数据库设置格式
|
7天前
|
安全 编译器 API
程序与技术分享:C#调用DLL的几种方法
程序与技术分享:C#调用DLL的几种方法
11 0
|
7天前
|
存储 关系型数据库 MySQL
|
7天前
|
存储 SQL 关系型数据库
|
2天前
|
XML Java 关系型数据库
Action:Consider the following: If you want an embedde ,springBoot配置数据库,补全springBoot的xml和mysql配置信息就好了
Action:Consider the following: If you want an embedde ,springBoot配置数据库,补全springBoot的xml和mysql配置信息就好了
|
2天前
|
关系型数据库 MySQL 数据库
关系型数据库mysql数据增量恢复
【7月更文挑战第3天】
11 2
|
2天前
|
关系型数据库 MySQL Shell
关系型数据库mysql数据完全恢复
【7月更文挑战第3天】
10 2