ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新

2024-08-28 13:18

本文主要是介绍ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. 要素的添加

ArcGIS Engine中,主要有两个方法用于要素的添加:

  • Using IFeatureClass.CreateFeature followed by IFeature.Store
  • Using IFeatureClass.CreateFeatureBuffer with an insert cursor 

批量插入feature,如果用feature.store()方法,在图层中一个个地插入要素,较之同时使用insert cursor与feature buffer方法,会慢很多。

因为后者触发的事件和复杂行为比较少(比如说没有引发因拓扑关系产生的行为)。


2. 要素的删除

删除feature,一个个删除就用IFeature.Delete方法即可,此处不再赘述,只写一种批量删除的方法,用于ITable是针对数据库进行操作的,所以速度很快。

The best approach to take when deleting features depends on two factors, how many features are being deleted and whether the data source is a local geodatabase or an ArcSDE geodatabase.

In the simplest case, a single feature that has already been retrieved can be deleted by callingIFeature.Delete. If bulk features are being deleted and the geodatabase is an ArcSDE geodatabase, the most efficient approach requires the use of a search cursor and the IFeature.Delete method.

On the other hand, if the geodatabase is a local geodatabase (a file or personal geodatabase), the most efficient method for bulk deletion is theITable.DeleteSearchedRows method.

示例:

[csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ///<summary>  
  2. ///删除某featurelayer中所有feature  
  3. ///</summary>  
  4. ///<param name="pLayer">操作的涂层</param>  
  5. ///<remarks>该方法可以给一个queryfilter,进行删除符合条件的features</remarks>  
  6. private void DeleteAllFeatures(IFeatureLayer pLayer, <code></code>IQueryFilter queryFilter)  
  7. {  
  8.   ITable pTable = pLayer.FeatureClass as ITable;  
  9.   pTable.DeleteSearchedRows(queryFilter);  

3. 属性的读取

在获取属性表的值时有多种方法:

方法一:

[csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ITable pTable = pLayer.FeatureClass as ITable;  
  2. clsFldValue = pTable.GetRow(i).get_Value(clsFldIndex); 
方法二:

[csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);  
  2. IFeature feature = FCursor.NextFeature();  
  3. if (feature == nullreturn null;  
  4. (2)clsFldValue = feature.get_Value(clsFldIndex);  
  5. feature = FCursor.NextFeature(); 

用Environment.TickCount进行代码执行时间测试,结果发现方法一读取整个表的时间为4984ms,而方法二读取同一个属性给的时间仅为32 ms,法二的执行效率是法一的156倍!!!

完整测试代码如下:

[csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1.  IFeatureLayer pLayer = Utilities.GetLayerByName((string)cmbRegLayers.SelectedItem, m_mapControl) as IFeatureLayer;  
  2.  IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);  
  3.  IFeature feature = FCursor.NextFeature();  
  4.   
  5.  int t = Environment.TickCount;  
  6.   
  7.  object clsFldValue=null;  
  8.  for (int i = 0; i < pLayer.FeatureClass.FeatureCount(null); i++)  
  9.  {  
  10.      clsFldValue = feature.get_Value(3);  
  11.      feature = FCursor.NextFeature();  
  12.  }  
  13.   
  14.  t = Environment.TickCount - t;  
  15.  MessageBox.Show(t.ToString());  
  16.   
  17.  ITable pTable = pLayer.FeatureClass as ITable;  
  18.   
  19.  t = Environment.TickCount;  
  20.   
  21.  for (int i = 0; i < pTable.RowCount(null); i++)  
  22.      clsFldValue = pTable.GetRow(i).get_Value(3);  
  23.  t = Environment.TickCount - t;  
  24.  MessageBox.Show(t.ToString());  

4.属性的更新

一、当将一批数据更新为某一相同的属性时,使用ITable.UpdateSearchedRows效率会很高。

示例如下:

  1. // Find the position of the field that will be updated.  
  2. int typeFieldIndex = featureClass.FindField("TYPE");  
  3.   
  4. // Create a query filter defining which fields will be updated  
  5. // (the subfields) and how to constrain which rows are updated  
  6. // (the where clause).  
  7. IQueryFilter queryFilter = new QueryFilterClass  
  8. {  
  9.     SubFields = "TYPE", WhereClause = "LANE_COUNT = 4"  
  10. };  
  11.   
  12. // Create a ComReleaser for buffer management.  
  13. using(ComReleaser comReleaser = new ComReleaser())  
  14. {  
  15.     // Create a feature buffer containing the values to be updated.  
  16.     IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();  
  17.     featureBuffer.set_Value(typeFieldIndex, "Highway");  
  18.     comReleaser.ManageLifetime(featureBuffer);  
  19.   
  20.     // Cast the class to ITable and perform the updates.  
  21.     ITable table = (ITable)featureClass;  
  22.     IRowBuffer rowBuffer = (IRowBuffer)featureBuffer;  
  23.     table.UpdateSearchedRows(queryFilter, rowBuffer);  

二、逐条更新记录

 这种方式中可有三种方法,如下:

(1)

  1. for (int i = 0; i < pTable.RowCount(null); i++)  
  2. {  
  3.     pRow = pTable.GetRow(i);  
  4.     pRow.set_Value(2, i + 6);  
  5.     pRow.Store();  
  6. }  
(2)
  1. IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);  
  2. IFeature feature = FCursor.NextFeature();  
  3.   
  4. for (int i = 0; i < featureNum; i++)  
  5. {  
  6.   
  7.     feature.set_Value(2, i);  
  8.     feature.Store();  
  9.     feature = FCursor.NextFeature();  
  10. }
(3)

  1. ICursor pCursor =pTable.Update(nullfalse);  
  2. pRow = pCursor.NextRow();  
  3. for (int i = 0; i < pTable.RowCount(null); i++)  
  4. {  
  5.     pRow.set_Value(2, i + 6);  
  6.     pCursor.UpdateRow(pRow);  
  7.     pRow = pCursor.NextRow();  
  8. }  

试验数据为320条记录,三种方法的运行时间为:法(1)为40297ms;法(2)34922ms为;法(3)为219ms.

可见运用IFeature和IRow的Store方法更新速度都很慢,用ICursor 的UpdateRow方法速度很快,分别是前两者效率的184倍、159倍!!

参考:

Creating features http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000049v000000

Updating Features http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002rs000000

插入和删除Featureclass中feature的几种方法(VB.Net) http://www.cnblogs.com/wall/archive/2008/12/05/1348646.html

Arcengine效率探究之一——属性的读取 http://blog.csdn.net/lk103852503/article/details/6566652

Arcengine效率探究之二——属性的更新 http://blog.csdn.net/lk103852503/article/details/6570748


这篇关于ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1114867

相关文章

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分

MySQL 删除数据详解(最新整理)

《MySQL删除数据详解(最新整理)》:本文主要介绍MySQL删除数据的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、前言二、mysql 中的三种删除方式1.DELETE语句✅ 基本语法: 示例:2.TRUNCATE语句✅ 基本语

一文详解Git中分支本地和远程删除的方法

《一文详解Git中分支本地和远程删除的方法》在使用Git进行版本控制的过程中,我们会创建多个分支来进行不同功能的开发,这就容易涉及到如何正确地删除本地分支和远程分支,下面我们就来看看相关的实现方法吧... 目录技术背景实现步骤删除本地分支删除远程www.chinasem.cn分支同步删除信息到其他机器示例步骤

python删除xml中的w:ascii属性的步骤

《python删除xml中的w:ascii属性的步骤》使用xml.etree.ElementTree删除WordXML中w:ascii属性,需注册命名空间并定位rFonts元素,通过del操作删除属... 可以使用python的XML.etree.ElementTree模块通过以下步骤删除XML中的w:as

MySQL追踪数据库表更新操作来源的全面指南

《MySQL追踪数据库表更新操作来源的全面指南》本文将以一个具体问题为例,如何监测哪个IP来源对数据库表statistics_test进行了UPDATE操作,文内探讨了多种方法,并提供了详细的代码... 目录引言1. 为什么需要监控数据库更新操作2. 方法1:启用数据库审计日志(1)mysql/mariad

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

如何在Mac上彻底删除Edge账户? 手动卸载Edge浏览器并清理残留文件技巧

《如何在Mac上彻底删除Edge账户?手动卸载Edge浏览器并清理残留文件技巧》Mac上的Edge账户里存了不少网站密码和个人信息,结果同事一不小心打开了,简直尴尬到爆炸,想要卸载edge浏览器并清... 如果你遇到 Microsoft Edge 浏览器运行迟缓、频繁崩溃或网页加载异常等问题,可以尝试多种方

Python打印对象所有属性和值的方法小结

《Python打印对象所有属性和值的方法小结》在Python开发过程中,调试代码时经常需要查看对象的当前状态,也就是对象的所有属性和对应的值,然而,Python并没有像PHP的print_r那样直接提... 目录python中打印对象所有属性和值的方法实现步骤1. 使用vars()和pprint()2. 使

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字