ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新
ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新
来自:http://blog.csdn.net/freewaywalker/article/details/23703863
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.
示例:
- ///<summary>
- ///删除某featurelayer中所有feature
- ///</summary>
- ///<param name="pLayer">操作的涂层</param>
- ///<remarks>该方法可以给一个queryfilter,进行删除符合条件的features</remarks>
- private void DeleteAllFeatures(IFeatureLayer pLayer, <code></code>IQueryFilter queryFilter)
- {
- ITable pTable = pLayer.FeatureClass as ITable;
- pTable.DeleteSearchedRows(queryFilter);
- }
3. 属性的读取
在获取属性表的值时有多种方法:
方法一:
- ITable pTable = pLayer.FeatureClass as ITable;
- clsFldValue = pTable.GetRow(i).get_Value(clsFldIndex);
方法二:
- IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
- IFeature feature = FCursor.NextFeature();
- if (feature == null) return null;
- clsFldValue = feature.get_Value(clsFldIndex);
- feature = FCursor.NextFeature();
用Environment.TickCount进行代码执行时间测试,结果发现方法一读取整个表的时间为4984ms,而方法二读取同一个属性给的时间仅为32 ms,法二的执行效率是法一的156倍!!!
完整测试代码如下:
- IFeatureLayer pLayer = Utilities.GetLayerByName((string)cmbRegLayers.SelectedItem, m_mapControl) as IFeatureLayer;
- IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
- IFeature feature = FCursor.NextFeature();
- int t = Environment.TickCount;
- object clsFldValue=null;
- for (int i = 0; i < pLayer.FeatureClass.FeatureCount(null); i++)
- {
- clsFldValue = feature.get_Value(3);
- feature = FCursor.NextFeature();
- }
- t = Environment.TickCount - t;
- MessageBox.Show(t.ToString());
- ITable pTable = pLayer.FeatureClass as ITable;
- t = Environment.TickCount;
- for (int i = 0; i < pTable.RowCount(null); i++)
- clsFldValue = pTable.GetRow(i).get_Value(3);
- t = Environment.TickCount - t;
- MessageBox.Show(t.ToString());
4.属性的更新
一、当将一批数据更新为某一相同的属性时,使用ITable.UpdateSearchedRows效率会很高。
示例如下:
- // Find the position of the field that will be updated.
- int typeFieldIndex = featureClass.FindField("TYPE");
- // Create a query filter defining which fields will be updated
- // (the subfields) and how to constrain which rows are updated
- // (the where clause).
- IQueryFilter queryFilter = new QueryFilterClass
- {
- SubFields = "TYPE", WhereClause = "LANE_COUNT = 4"
- };
- // Create a ComReleaser for buffer management.
- using(ComReleaser comReleaser = new ComReleaser())
- {
- // Create a feature buffer containing the values to be updated.
- IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
- featureBuffer.set_Value(typeFieldIndex, "Highway");
- comReleaser.ManageLifetime(featureBuffer);
- // Cast the class to ITable and perform the updates.
- ITable table = (ITable)featureClass;
- IRowBuffer rowBuffer = (IRowBuffer)featureBuffer;
- table.UpdateSearchedRows(queryFilter, rowBuffer);
- }
二、逐条更新记录
这种方式中可有三种方法,如下:
(1)
- for (int i = 0; i < pTable.RowCount(null); i++)
- {
- pRow = pTable.GetRow(i);
- pRow.set_Value(2, i + 6);
- pRow.Store();
- }
(2)
- IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
- IFeature feature = FCursor.NextFeature();
- for (int i = 0; i < featureNum; i++)
- {
- feature.set_Value(2, i);
- feature.Store();
- feature = FCursor.NextFeature();
- }
(3)
- ICursor pCursor =pTable.Update(null, false);
- pRow = pCursor.NextRow();
- for (int i = 0; i < pTable.RowCount(null); i++)
- {
- pRow.set_Value(2, i + 6);
- pCursor.UpdateRow(pRow);
- pRow = pCursor.NextRow();
- }
试验数据为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效率探究——要素的添加和删除、属性的读取和更新的更多相关文章
- [转] ArcGIS engine中气泡标注的添加、修改
小生 原文 ArcGIS engine中气泡标注的添加.修改! 你微微地笑着,不同我说什么话.而我觉得,为了这个,我已等待得久了. ...
- vue组件上动态添加和删除属性
1.vue组件上动态添加和删除属性 // 添加 this.$set(this.obj, 'propName', val) // 删除 this.$delete(this.obj, 'propName' ...
- arcgis engine 监听element的添加、更新和删除事件(使用IGraphicsContainerEvents)
IGraphicsContainerEvents Interface 如何监听 element事件? 如,当我们在Mapcontrol上添加.删除.更新了一个Element后,如何捕捉到这个事件? ...
- js 为对象添加和删除属性
对于一个普通的js对象: var obj = { name:"mary", age:21 } 如果我们要对它添加新属性的话可以使用下列方式: obj.address = " ...
- 在js中为对象添加和删除属性
对于一个普通的js对象: var obj = { name:"mary", age:21 } 如果我们要对它添加新属性的话可以使用下列方式: obj.address = " ...
- arcgis engine 监听element的添加、更新和删除事件(使用IMovePointFeedback)
VB代码: 复制进程序稍作修改变量名和事件逻辑即可使用. Members AllPropertiesMethodsInheritedNon-inherited Description Displa ...
- ArcEngine查询、添加、删除要素的方法
原文 ArcEngine查询.添加.删除要素的方法 1.查找数据 1).利用FeaturCursor进行空间查询 //空间查询 ISpatialFilter spatialFilter = new S ...
- 使用Advanced Installer 自动部署 Arcgis Engine Runtime 10.0
原文:使用Advanced Installer 自动部署 Arcgis Engine Runtime 10.0 目前采用Arcgis9.2 + c#(vs2008)作为程序开发平台,是一个不错的搭配. ...
- Arcgis engine 指定图层对要素进行创建、删除等操作
Arcgis engine 指定图层创建点要素 在指定的图层上创建一个点要素,点要素的位置是通过X,Y坐标指定的,下面是具体的注释 .其中 和IFeatureClassWrite接口有关的代码不要好像 ...
随机推荐
- R in action读书笔记(19)第十四章 主成分和因子分析
第十四章:主成分和因子分析 本章内容 主成分分析 探索性因子分析 其他潜变量模型 主成分分析(PCA)是一种数据降维技巧,它能将大量相关变量转化为一组很少的不相关变量,这些无关变量称为主成分.探索性因 ...
- mysql中int(1)与int(10)的区别
INT[(M)] [UNSIGNED] [ZEROFILL] 普通大小的整数.带符号的范围是-2147483648到2147483647.无符号的范围是0到4294967295. INT(1) 和 I ...
- python文件的读写的模式
<1>打开文件 在python,使用open函数,可以打开一个已经存在的文件,或者创建一个新文件 open(文件名,访问模式) 示例如下: f = open('test.txt', 'w' ...
- viewport 640宽的做法 针对iphone和安卓单独设置
<!DOCTYPE html> <html lang="ch"> <head> <meta charset="utf-8&quo ...
- 输入一个字符串输出ASCII的十六进制值
#include <stdio.h> #include <string.h> #define LEN 1024 void main() { char s[LEN] = &quo ...
- springboot实现web应用过程中的摸爬打滚(持续更新ing)
最近在做公司的网站项目,后端用到springboot.怎么说呢,记录总结一下自己开发过程中遇到的坑和一些心得体会,以及一些技巧.方便以后回顾复习,也供同行们参考. 开发环境:eclipse2018-1 ...
- 五、面向切面的spring(1)
spring的依赖注入看完了,接下来是spring中与DI一并重要的AOP了,开始吧,GO. 在软件开发中,散布于应用中多处的功能被称为横切发关注点,通常来讲,这些横切关注点从概念上市与应用的业务逻辑 ...
- Python模块 shelve xml configparser hashlib
常用模块1. shelve 一个字典对象模块 自动序列化2.xml 是一个文件格式 写配置文件或数据交换 <a name="hades">123</a>3. ...
- 如果由你来设计 12306.cn,你会怎么设计?
作者:huangkun链接:https://www.zhihu.com/question/20017917/answer/15272038来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...
- nginx配置文件+本地测试请求转发到远程服务器+集群
1 在本地测试1 众所周知,nginx是一个反向代理的服务器,主要功能即为实现负载均衡和动静分离.在别的我别的文章有详细的nginx(Windows)相关介绍教程. 由于自己安装的nginx在本地的计 ...