http://blog.csdn.net/lk103852503/article/details/6566652

在写一个对属性表的统计函数时,发现执行速度奇慢无比,百思不得其解,其实算法并不复杂,后来逐句排查终于发现竟是Arcengine的函数读取属性值的问题。

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

方法一:

ITable pTable = pLayer.FeatureClass as ITable;

clsFldValue = pTable.GetRow(i).get_Value(3);

方法二:

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());

至于为什么使用ITable 读取属性值速度如此之慢,不得而知,望有高人指点。

另外,在ESRI中国社区中也有一帖子讨论执行速度的问题,或者能为类似问题做些提示。此贴内容如下:

目标是想将原数据库中的点信息(x,y经纬度坐标,度格式),添加到FeatureClass中,数据库中大概有10000条数据,全部添加到FeatureClass中大概需要半小时以上

DataSet ds = loadExcel("d://aaa.xls");

IFeature feature = featureClass.CreateFeature();

IFields fields = featureClass.Fields;

for(int i=0;i<ds.Tables[0].Rows.Count;i++)

{

DataRow row = ds.Tables[0].Rows[i];

string xl = Convert.ToString(row[0]);

string x = Convert.ToDouble(row[1]);

string y = Convert.ToDouble(row[2]);

//....其它数据库中字段

//创建点对象

IPoint point = new PointClass();

point.X = x;

point.Y = y;

//设置Fields域

feature.set_Value(fields.FindField("线路"),xl);

feature.set_Value(fields.FindField("经度"),x);

feature.set_Value(fields.FindField("纬度"),y);

//保存点对象

feature.Shape = point;

feature.Store();

}

改进后:

DataSet ds = loadExcel("d://aaa.xls");

IFeatureBuffer featureBuffer;

IFeatureCursor cur = featureClass.Insert(true);

IPoint point;

IFields fields = featureClass.Fields;

for(int i=0;i<ds.Tables[0].Rows.Count;i++)

{

DataRow row = ds.Tables[0].Rows[i];

string xl = Convert.ToString(row[0]);

string x = Convert.ToDouble(row[1]);

string y = Convert.ToDouble(row[2]);

//....其它数据库中字段

//创建点对象

point = new PointClass();

point.X = x;

point.Y = y;

featureBuffer = featureClass.CreateFeatureBuffer();

//设置Fields域

featureBuffer.set_Value(fields.FindField("线路"),xl);

featureBuffer.set_Value(fields.FindField("经度"),x);

featureBuffer.set_Value(fields.FindField("纬度"),y);

//保存点对象

featureBuffer.Shape = point;

cur.InsertFeature(featureBuffer);

}

可以看出改进后使用了eatureClass.CreateFeatureBuffer方法,使效率大大提高。

Arcengine效率探究之一——属性的读取(转载)的更多相关文章

  1. 【转载】Arcengine效率探究之二——属性的更新

    文转载自hymyjl2010<Arcengine效率探究之二——属性的更新>   修改一批要素的属性有多种方法,当数据量较大时,若选择不当可能会大大影响速度. 一.IRowBuffer 方 ...

  2. Arcengine效率探究之二——属性的更新(转载)

    http://blog.csdn.net/lk103852503/article/details/6570748 修改一批要素的属性有多种方法,当数据量较大时,若选择不当可能会大大影响速度. 一.IR ...

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

    ArcGIS Engine效率探究——要素的添加和删除.属性的读取和更新 来自:http://blog.csdn.net/freewaywalker/article/details/23703863 ...

  4. java属性文件读取,属性修改

    /** * 属性文件读取 * @author bestmata * */ public class CommUtil { private static Logger logger=Logger.get ...

  5. 用元类和__getattribute__改变类属性的读取方式

    首先,需要知道两点: 类本身是type类的实例 __getattribute__ 可以改变类实例的属性的读取方式(http://www.cnblogs.com/blackmatrix/p/568148 ...

  6. pre-commit 钩子,代码质量检查:在 vue-cli 3.x 版本中,已经使用尤大改写的yorkie,yorkie实际是fork husky,然后做了一些定制化的改动,使得钩子能从package.json的 "gitHooks"属性中读取

    pre-commit 钩子,代码质量检查:在 vue-cli 3.x 版本中,已经使用尤大改写的yorkie,yorkie实际是fork husky,然后做了一些定制化的改动,使得钩子能从packag ...

  7. 使用jQuery匹配文档中所有的li元素,返回一个jQuery对象,然后通过数组下标的方式读取jQuery集合中第1个DOM元素,此时返回的是DOM对象,然后调用DOM属性innerHTML,读取该元素 包含的文本信息

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. SpringBoot入门 (二) 属性文件读取

    在上一篇中介绍了在idea中创建springboot工程及使用web工程输出“helloworld”到前端页面,本文学习在springboot工程中读取属性文件中的属性值. 一 自定义属性 在appl ...

  9. 深入探究.Net Core Configuration读取配置的优先级

    前言     在之前的文章.Net Core Configuration源码探究一文中我们曾解读过Configuration的工作原理,也.Net Core Configuration Etcd数据源 ...

随机推荐

  1. 数据库迁移之从oracle 到 MySQL最简单的方法

    数据库迁移之从oracle 到 MySQL最简单的方法 因工作需要将oracle数据库换到MySQL数据库,数据量比较大,百万级别的数据,表也比较多,有没有一种既快捷又安全的方法呢?答案是肯定的,下面 ...

  2. mysql5.7 误删管理员root账户

    1.停止数据库,并在mysql配置文件my.cnf中添加skip-grant-tables参数到[mysqld]配置块中 2. 执行 systemctl start mysqld 3. 执行 mysq ...

  3. make报错

    笔记本Ubuntu16.04环境下,进入项目的src目录下执行make操作,发现报如下错误 /bin/sh: 1: /usr/bin/libtool: not found makefile:89: r ...

  4. WMS - resource info

    Description This sample shows how to work with an OGC Web Map Service (WMS). When WMSLayers are adde ...

  5. python面试题(一)

    1.通过代码实现如下转换: 二进制转换成十进制:v = “0b1111011” #先将其转换为字符串,再使用int函数,指定进制转换为十进制. print(int("0b1111011&qu ...

  6. 关于Maven配置的一些标签含义(后续逐渐补充)

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  7. leetcode16—3 Sum Closet

    Given an array nums of n integers and an integer target, find three integers in nums such that the s ...

  8. JAVA框架 Mybaits

     注意:我们在resultType中,对于selectlist方法也是projo类.resultType参数的含义是list的泛型的类型. 一:jar包下载: https://github.com/m ...

  9. 609E- Minimum spanning tree for each edge

    Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n ...

  10. day39

    今日内容: 1.对于表,库,记录的基本操作 2.数据库引擎的了解 3.表的详细 4.数据类型的掌握 1.回顾昨日对于表,库,记录的基本操作 库 增: create database mydb2; 删: ...