• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
ArcEngine效率探究之二——属性的更新

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

一、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());

 

posted on 2013-06-27 10:01  bobird  阅读(727)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3