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. File API

    ES5 推出了一系列的 API: BLOB (二进制大对象) File (文件接口,基于 BLOB,但是增加了文件相关的方法,比如路径,大小) FileList (借助 <input type= ...

  2. 关于Vue的nextTick的一点小理解

    官方文档表示:为了在数据变化之后等待Vue完成更新DOM,可以在数据变化之后立即执行Vue.$nextTick(callback),这样回调函数就可以在数据变化之后立即执行. 这段话的意思是: 例如: ...

  3. MySQL双主.md

    MySQL 双主配置 环境说明 系统 IP 主机名 mysql版本 CentOS 6.8 192.168.197.61 C6-node1 5.6.36 CentOS 6.8 192.168.197.6 ...

  4. Flume学习之路 (二)Flume的Source类型

    一.概述 官方文档介绍:http://flume.apache.org/FlumeUserGuide.html#flume-sources 二.Flume Sources 描述 2.1 Avro So ...

  5. Jemeter编写脚本(五类常见请求)

    http://blog.csdn.net/musen518/article/details/50601364   (原文地址) (Windows系统 点击 F12 调出开发者工具,选择Network, ...

  6. rlwrap与历史命令

    # yum install rlwrap $ vi .bash_profile alias sqlplus='rlwrap sqlplus'alias rman='rlwrap rman' 或者 l ...

  7. Python2.7-datetime

    datetime 模块用于操作日期时间模块内定义了5个类:date,time,datetime,timedelta,tzinfo 1.timedelta对象,代表一个时间间隔datetime.time ...

  8. Android DatePickerDialog使用案例

    DatePickerDialog提供了一个弹出的Dialog供用户选择日期. 在这里分享一下其使用方法,效果图如下: DatePickerActivity.java package com.yw.my ...

  9. vmware共享文件夹

    环境: VMware Workstation 11.0 虚拟机中的系统:Ubuntu 16.04 物理机:window 7 安装好vmware tools后在 /mnt/hgfs 里没有东西,是空白的 ...

  10. 【本地服务器】用nginx进行反向代理处理(windows)

    在通过json-server搭建本地服务器得到 http://localhost:3000/todos   的基础上,要想将接口改为www.test.com/todos这样的形式 ,则需要用nginx ...