1. 程式人生 > >ArcGIS Engine效率探究之(一)屬性的讀取

ArcGIS Engine效率探究之(一)屬性的讀取

   對屬性表的統計函式時,發現執行速度奇慢無比,百思不得其解,其實演算法並不複雜,後來逐句排查終於發現竟是 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方法,使效率大大提高。