Arcengine效率探究之二——属性的更新(转载)

http://blog.csdn.net/lk103852503/article/details/6570748

修改一批要素的属性有多种方法,当数据量较大时,若选择不当可能会大大影响速度。

一、IRowBuffer 方法

此法适用于将一批数据更新为某一相同的属性。

IQueryFilter pFilter = new QueryFilterClass();
pFilter.WhereClause = "Z='T'";
pFilter.SubFields = "Z";
int nIndex = pFeatureClass.FindField("Z");
ITable pTable = pFeatureClass as ITable;
IRowBuffer pBuffer = pTable.CreateRowBuffer();
pBuffer.set_Value(nIndex, "TT");
pTable.UpdateSearchedRows(pFilter, pBuffer);
Marshal.ReleaseComObject(pFilter);

当所要更新的属性各不相同时,上述方法就不能用了。

二、逐条更新记录

这种方式中可有三种方法,如下:

(1)

for (int i = 0; i < pTable.RowCount(null); i++)
            {
                pRow = pTable.GetRow(i);
                pRow.set_Value(2, i + 6);
                pRow.Store();
            }

(2)

IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
 IFeature feature = FCursor.NextFeature();

for (int i = 0; i < featureNum; i++)
            {

feature.set_Value(2, i);
                feature.Store();
                feature = FCursor.NextFeature();
            }

(3)

ICursor pCursor =pTable.Update(null, false);
            pRow = pCursor.NextRow();
            for (int i = 0; i < pTable.RowCount(null); i++)
            {
                pRow.set_Value(2, i + 6);
                pCursor.UpdateRow(pRow);
                pRow = pCursor.NextRow();

}
试验数据为320条记录,三种方法的运行时间为:法(1)为40297ms;法(2)34922ms为;法(3)为219ms.

可见运用IFeature和IRow的Store方法更新速度都很慢,用ICursor 的UpdateRow方法速度很快,分别是前两者效率的184倍、159倍!!完整测试代码如下:

IFeatureLayer pLayer = Utilities.GetLayerByName((string)cmbRegLayers.SelectedItem, m_mapControl) as IFeatureLayer;
            ITable pTable = pLayer.FeatureClass as ITable;
            int t = 0;

IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
            IFeature feature = FCursor.NextFeature();
            int featureNum = pLayer.FeatureClass.FeatureCount(null);
            t = Environment.TickCount;
            for (int i = 0; i < featureNum; i++)
            {

feature.set_Value(2, i);
                feature.Store();
                feature = FCursor.NextFeature();
            }
            t = Environment.TickCount - t;
            MessageBox.Show(t.ToString());

t = Environment.TickCount;
            ICursor pCursor =pTable.Update(null, false);
            IRow pRow = pCursor.NextRow();
            for (int i = 0; i < pTable.RowCount(null); i++)
            {
                pRow.set_Value(2, i + 6);
                pCursor.UpdateRow(pRow);
                pRow = pCursor.NextRow();

}

t = Environment.TickCount - t;
            MessageBox.Show(t.ToString());

t = Environment.TickCount;
            for (int i = 0; i < pTable.RowCount(null); i++)
            {
                pRow = pTable.GetRow(i);
                pRow.set_Value(2, i + 6);
                pRow.Store();
            }

t = Environment.TickCount - t;
            MessageBox.Show(t.ToString());

上一篇:Elasticsearch template(待续...)


下一篇:python的time