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方法,使效率大大提高。

 


发布了40 篇原创文章 · 获赞 6 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/mrbaolong/article/details/47803497