Arcengine效率探究之一——属性的读取 复
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 ms156
一、FeatureCursor方法
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 方法读取
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;iDataRow 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;iDataRow 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