zoukankan      html  css  js  c++  java
  • 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());

  • 相关阅读:
    Docker 给 故障停掉的 container 增加 restart 参数
    使用docker化的nginx 反向代理 docker化的GSCloud 的方法
    apache benchmark 的简单安装与测试
    mysql5.7 的 user表的密码字段从 password 变成了 authentication_string
    Windows 机器上面同时安装mysql5.6 和 mysql5.7 的方法
    python4delphi 安装
    见证下神奇的时刻
    windows下面安装Python和pip终极教程
    python如何安装pip和easy_installer工具
    Tushare的安装
  • 原文地址:https://www.cnblogs.com/bobzhangfw/p/3147895.html
Copyright © 2011-2022 走看看