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

来自:http://blog.csdn.net/freewaywalker/article/details/23703863

分类: ArcNotes2014-04-14 20:56 1781人阅读 评论(0) 收藏 举报

1. 要素的添加

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

批量插入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.

示例:

  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);
  10. }

3. 属性的读取

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

方法一:

  1. ITable pTable = pLayer.FeatureClass as ITable;
  2. clsFldValue = pTable.GetRow(i).get_Value(clsFldIndex);

方法二:

  1. IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
  2. IFeature feature = FCursor.NextFeature();
  3. if (feature == null) return null;
  4. clsFldValue = feature.get_Value(clsFldIndex);
  5. feature = FCursor.NextFeature();

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

完整测试代码如下:

  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. int t = Environment.TickCount;
  5. object clsFldValue=null;
  6. for (int i = 0; i < pLayer.FeatureClass.FeatureCount(null); i++)
  7. {
  8. clsFldValue = feature.get_Value(3);
  9. feature = FCursor.NextFeature();
  10. }
  11. t = Environment.TickCount - t;
  12. MessageBox.Show(t.ToString());
  13. ITable pTable = pLayer.FeatureClass as ITable;
  14. t = Environment.TickCount;
  15. for (int i = 0; i < pTable.RowCount(null); i++)
  16. clsFldValue = pTable.GetRow(i).get_Value(3);
  17. t = Environment.TickCount - t;
  18. 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. // Create a query filter defining which fields will be updated
  4. // (the subfields) and how to constrain which rows are updated
  5. // (the where clause).
  6. IQueryFilter queryFilter = new QueryFilterClass
  7. {
  8. SubFields = "TYPE", WhereClause = "LANE_COUNT = 4"
  9. };
  10. // Create a ComReleaser for buffer management.
  11. using(ComReleaser comReleaser = new ComReleaser())
  12. {
  13. // Create a feature buffer containing the values to be updated.
  14. IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
  15. featureBuffer.set_Value(typeFieldIndex, "Highway");
  16. comReleaser.ManageLifetime(featureBuffer);
  17. // Cast the class to ITable and perform the updates.
  18. ITable table = (ITable)featureClass;
  19. IRowBuffer rowBuffer = (IRowBuffer)featureBuffer;
  20. table.UpdateSearchedRows(queryFilter, rowBuffer);
  21. }

二、逐条更新记录

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

(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. for (int i = 0; i < featureNum; i++)
  4. {
  5. feature.set_Value(2, i);
  6. feature.Store();
  7. feature = FCursor.NextFeature();
  8. }

(3)

  1. ICursor pCursor =pTable.Update(null, false);
  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效率探究——要素的添加和删除、属性的读取和更新的更多相关文章

  1. [转] ArcGIS engine中气泡标注的添加、修改

    小生 原文 ArcGIS engine中气泡标注的添加.修改! 你微微地笑着,不同我说什么话.而我觉得,为了这个,我已等待得久了.                                   ...

  2. vue组件上动态添加和删除属性

    1.vue组件上动态添加和删除属性 // 添加 this.$set(this.obj, 'propName', val) // 删除 this.$delete(this.obj, 'propName' ...

  3. arcgis engine 监听element的添加、更新和删除事件(使用IGraphicsContainerEvents)

    IGraphicsContainerEvents Interface 如何监听 element事件? 如,当我们在Mapcontrol上添加.删除.更新了一个Element后,如何捕捉到这个事件?   ...

  4. js 为对象添加和删除属性

    对于一个普通的js对象: var obj = { name:"mary", age:21 } 如果我们要对它添加新属性的话可以使用下列方式: obj.address = " ...

  5. 在js中为对象添加和删除属性

    对于一个普通的js对象: var obj = { name:"mary", age:21 } 如果我们要对它添加新属性的话可以使用下列方式: obj.address = " ...

  6. arcgis engine 监听element的添加、更新和删除事件(使用IMovePointFeedback)

    VB代码: 复制进程序稍作修改变量名和事件逻辑即可使用. Members   AllPropertiesMethodsInheritedNon-inherited Description Displa ...

  7. ArcEngine查询、添加、删除要素的方法

    原文 ArcEngine查询.添加.删除要素的方法 1.查找数据 1).利用FeaturCursor进行空间查询 //空间查询 ISpatialFilter spatialFilter = new S ...

  8. 使用Advanced Installer 自动部署 Arcgis Engine Runtime 10.0

    原文:使用Advanced Installer 自动部署 Arcgis Engine Runtime 10.0 目前采用Arcgis9.2 + c#(vs2008)作为程序开发平台,是一个不错的搭配. ...

  9. Arcgis engine 指定图层对要素进行创建、删除等操作

    Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...

随机推荐

  1. web 自动化测试 selenium基础到应用(目录)

    第一章   自动化测试前提及整体介绍 1-1功能测试和自动化测试的区别 1-2自动化测试流程有哪些 1-3自动化测试用例和手工用例的区别 1-4 自动化测试用例编写 1-5 selenium的优势以及 ...

  2. JVM 优点与缺点的深入分析

    Java 最初诞生的时候,它可以说是其他语言的进化版.不仅因为Java很简单,而且这一进化的语言还是一个可以运行第三方硬件字节码的虚拟机.它还是垃圾收集站,从而令存储管理和内核转储(core dump ...

  3. IntelliJ IDEA导入JDK出现The selected directory is not a valid home for JDK问题的解决方法

    JDK版本与IDEA版本不兼容: JDK版本过高可能会造成这个问题,需与IDEA相兼容的JDK才行. 比如,用IDEA2016.3.8版本的,JDK用jdk-10.0.1_windows-x64_bi ...

  4. 前复权是从今天的价格倒推 后复权是从上市价格前推 不复权就是原始K线。

    前复权是从今天的价格倒推 后复权是从上市价格前推 不复权就是原始K线.

  5. 编写图形界面下的Java Swing程序,接受用户输入的两个数据为上下限,然后输出上、下限之间的所有素数。(结果部分每行显示10个数据)

    这个代码我整体写的比较简单,读者可以简单参考一下,对人家题目要求略微修改了一下,多加了一个“置空”按钮.下图为我设计的界面 运行程序后的截图请看我后面的截图: package com.wangshil ...

  6. jquery /css3 全屏的渐变背景

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. switch、try-catch

    记录 1. 使用对象代替 switch 和 if-else 2. 根据返回数据是否能转成对象,取值 如果返回是数字字符串,直接返回,如果返回是对象,取对应的key值,再返回 其它情况,返回空 {{ o ...

  8. 2018 CCPC 桂林站(upc复现赛)补题

    2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...

  9. Linux基础学习二

    新建分区:fdisk /dev/sda(a代表第一块硬盘)                   建完后w保存 更新分区表:partprobe mkfs.ext4 /dev/sdb{1..3} : 格式 ...

  10. vue中的表单验证

    http://www.cnblogs.com/luoxuemei/p/9295506.html /*是否合法IP地址*/ export function validateIP(rule, value, ...