ArcGIS Engine效率探究之(一)属性的读取

原文链接:http://blog.csdn.net/lk103852503/article/details/6566652

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

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

  方法一:

 

ITable pTable = pFeatureClass as ITable;

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

 方法二:

 

 

IFeatureCursor pFCursor = pFeatureClass.Search(new QueryFilterClass(), false);

IFeature pFeature = pFCursor.NextFeature();

if (pFeature == null) return null;

pValue = pFeature.get_Value(pIndex);

pFeature = pFCursor.NextFeature();

方法二明显要快于方法一

 

  实例测试:

   

//目标是想将原数据库中的点信息(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方法,使效率大大提高。

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值