1、查找数据

1)、利用FeaturCursor进行空间查询

//空间查询
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = envelope;//指定几何体
String shpFld = featureClass.ShapeFieldName;
spatialFilter.GeometryField = shpFld;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;//相交
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter = (IQueryFilter)spatialFilter;
IFeatureCursor searchCursor = featureClass.Search(queryFilter, true);
IFeature feature = searchCursor.NextFeature(); int n = ;
while (feature != null){
n++;
feature = baseCursor.NextFeature();
}

2)、利用FeatureCursor在选择集中进行查询

IFeatureSelection pFeatureSelectio = pFeatureLayer as IFeatureSelection;
ICursor ppCursor;
pFeatureSelectio.SelectionSet.Search(null, false, out ppCursor);
IFeatureCursor pFeatureCursor = ppCursor as IFeatureCursor;
IFeature pFeature = pFeatureCursor.NextFeature();

3)、利用FeatureCursor进行属性查询

IQueryFilter pQueryFilter = new QueryFilterClass();
pQueryFilter.WhereClause = "PROJECTCODE = '" + this.ProjectNumTextBox.Text.Trim() + "'";
IFeatureCursor pFeatureCursor = LineFeaClass.Search(pQueryFilter, false);
IFeature pFeatureIfExit = pFeatureCursor.NextFeature();

用Environment.TickCount进行代码执行时间测试,结果发现4)读取整个表的时间为4984ms,而 3)读取同一个属性给的时间仅为32 ms,3)的执行效率是法一的156倍!!!

完整测试代码如下:

     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 = ; i < pLayer.FeatureClass.FeatureCount(null); i++)
{
clsFldValue = feature.get_Value();
feature = FCursor.NextFeature();
} t = Environment.TickCount - t;
MessageBox.Show(t.ToString()); ITable pTable = pLayer.FeatureClass as ITable; t = Environment.TickCount; for (int i = ; i < pTable.RowCount(null); i++)
clsFldValue = pTable.GetRow(i).get_Value();
t = Environment.TickCount - t;
MessageBox.Show(t.ToString());

4)属性表的方法读取属性值

ITable pTable = pLayer.FeatureClass as ITable;
clsFldValue = pTable.GetRow(i).get_Value(clsFldIndex);

2、 插入数据

ArcGIS Engine中,主要有两个方法用于要素的添加:

批量插入feature,如果用feature.store()方法,在图层中一个个地插入要素,较之同时使用insert cursor与feature buffer方法,会慢很多。

因为后者触发的事件和复杂行为比较少(比如说没有引发因拓扑关系产生的行为)。

1)、利用Insert Cursors和featureBuffer

IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
IFeatureCursor featureCursor = featureClass.Insert(true);
object featureOID;
featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "B Pierce");
for (int ic = ; ic < ; ic++)
{
featureBuffer.Shape = geometry;
featureOID = featureCursor.InsertFeature(featureBuffer);
}
featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "K Johnston");
for (int ic = ; ic < ; ic++)
{
featureBuffer.Shape = geometry
featureOID = featureCursor.InsertFeature(featureBuffer);
}
featureCursor.Flush();

2)、直接进行数据插入(Feature.Store方法)

IFeature newLineFeature = LineFeaClass.CreateFeature();                           

newLineFeature.Shape = pFeature.Shape;
int ii = newLineFeature.Fields.FindField(AreaZonalName); if (ii > )
{
newLineFeature.set_Value(ii, this.AnalysAreaComboBox.Text.Trim());
} newLineFeature.Store();

注:最好将编辑操作对象中,如下:

IDataset dataset = (IDataset)featureClass;

IWorkspace workspace = dataset.Workspace;

// Cast the workspace to the IWorkspaceEdit interface.

IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;

// Start an edit session and edit operation.

workspaceEdit.StartEditing(true);

workspaceEdit.StartEditOperation();

//在这里编写添加要素的代码。。。。。。。。。。。

// Stop editing.

workspaceEdit.StopEditOperation();

workspaceEdit.StopEditing(true);

3、数据删除 delete

删除feature,一个个删除就用IFeature.Delete方法即可,此处不再赘述,只写一种批量删除的方法,用于ITable是针对数据库进行操作的,所以速度很快。

The best approach to take when deleting features depends on two factors, how many features are being deleted and whether the data source is a local geodatabase or an ArcSDE geodatabase.

In the simplest case, a single feature that has already been retrieved can be deleted by callingIFeature.Delete. If bulk features are being deleted and the geodatabase is an ArcSDE geodatabase, the most efficient approach requires the use of a search cursor and the IFeature.Delete method.

On the other hand, if the geodatabase is a local geodatabase (a file or personal geodatabase), the most efficient method for bulk deletion is theITable.DeleteSearchedRows method.

方法1  ITable方法

///<summary>
///删除某featurelayer中所有feature
///</summary>
///<param name="pLayer">操作的涂层</param>
///<remarks>该方法可以给一个queryfilter,进行删除符合条件的features</remarks>
private void DeleteAllFeatures(IFeatureLayer pLayer, <code></code>IQueryFilter queryFilter)
{
  ITable pTable = pLayer.FeatureClass as ITable;
  pTable.DeleteSearchedRows(queryFilter);
}

方法2 迭代featureClass方法

IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("Parcels");
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "ZONING_S = 'R'";
IFeatureCursor updateCursor = featureClass.Update(queryFilter, false);
IFeature feature = updateCursor.NextFeature();
int m = ;
while (feature != null)
{
m++;
updateCursor.DeleteFeature(feature);
feature = updateCursor.NextFeature();
}

4、 数据更新 update 

4.1 逐条更新记录

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

(1)

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

(2)

    IFeatureCursor FCursor = pLayer.FeatureClass.Search(new QueryFilterClass(), false);
IFeature feature = FCursor.NextFeature(); for (int i = ; i < featureNum; i++)
{ feature.set_Value(, i);
feature.Store();
feature = FCursor.NextFeature();
}

(3)

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

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

可见运用IFeature和IRow的Store方法更新速度都很慢,用ICursor 的UpdateRow方法速度很快,分别是前两者效率的184倍、159倍!!

4.2 批量更新记录

IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("Parcels");

// 属性查询
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "ZONING_S = 'U'"; //利用FeatureCursor进行数据更新
IFeatureCursor updateCursor = featureClass.Update(queryFilter, false);
int fieldindex = featureClass.FindField("ZONING_S");
IFeature feature = updateCursor.NextFeature();
int m = ; while (feature != null)
{
m++;
feature.set_Value(fieldindex, "X");
updateCursor.UpdateFeature(feature);
feature = updateCursor.NextFeature();
}

当将一批数据更新为某一相同的属性时,使用ITable.UpdateSearchedRows效率会很高。

    // Find the position of the field that will be updated.
int typeFieldIndex = featureClass.FindField("TYPE"); // Create a query filter defining which fields will be updated
// (the subfields) and how to constrain which rows are updated
// (the where clause).
IQueryFilter queryFilter = new QueryFilterClass
{
SubFields = "TYPE", WhereClause = "LANE_COUNT = 4"
}; // Create a ComReleaser for buffer management.
using(ComReleaser comReleaser = new ComReleaser())
{
// Create a feature buffer containing the values to be updated.
IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
featureBuffer.set_Value(typeFieldIndex, "Highway");
comReleaser.ManageLifetime(featureBuffer); // Cast the class to ITable and perform the updates.
ITable table = (ITable)featureClass;
IRowBuffer rowBuffer = (IRowBuffer)featureBuffer;
table.UpdateSearchedRows(queryFilter, rowBuffer);
}

参考文章

ArcEngine查询、添加、删除要素的方法

ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新

ArcEngine查询、添加、删除要素的方法的更多相关文章

  1. js动态给table添加/删除tr的方法

    js动态给table添加/删除tr的方法. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ...

  2. mysql 查询 添加 删除 语句

    1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数据的 d ...

  3. js 查询 添加 删除 练习

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  4. JAVA连接MYSQL,查询 ,添加,删除,语句

        package com; import Java.sql.*;/** *//** * @author Administrator */public class ggg {    private ...

  5. python 对过时类或方法添加删除线的方法

    class Cat(Animal): def __init__(self): import warnings warnings.warn("Cat类带删除线了", Deprecat ...

  6. JS原生添加删除class的方法

    之前习惯了使用jquery的addClass的方法,然后就去找了下别人写的代码. [javascript] view plain copy function hasClass(obj,cls) { r ...

  7. 【225】ArcEngine 实现要素添加 & 删除

    参考:ArcGIS Engine效率探究——要素的添加和删除.属性的读取和更新 删除要素 //添加图层,显示在最上面 axMapControl1.AddShapeFile(@"D:\01-业 ...

  8. ArcGIS Engine中删除要素的几种方法总结

    转自原文 ArcGIS Engine中删除要素的几种方法总结 /// <summary> /// 通过IFeature.Delete方法删除要素 /// </summary> ...

  9. ArcEngine数据删除几种方法和性能比较

    转自原文 ArcEngine数据删除几种方法和性能比较 一.  几种删除方法代码 1.  查询结果中删除 private void Delete1(IFeatureClass PFeatureclas ...

随机推荐

  1. c#教程之事件处理函数的参数

    事件处理函数一般有两个参数,第一个参数(object sender)为产生该事件的对象的属性Name的值,例如上例单击标题为红色的按钮,第一个参数sender的值为button1.如上例标题为红色的按 ...

  2. bnuoj 31796 键盘上的蚂蚁(搜索模拟)

    http://www.bnuoj.com/bnuoj/contest_show.php?cid=2876#problem/31796 [题意]: 如题,注意大小写情况 [code]: #include ...

  3. Delaunay三角剖分

    Bowyer-Watson算法:1.假设已经生成了连接若干个顶点的Delaunay三角网格:2.加入一个新的节点,找出所有外接圆包含新加入节点的三角形,并将这些三角形删除形成一个空洞:3.空洞的节点与 ...

  4. swift苹果的下一代语言

    http://numbbbbb.github.io/the-swift-programming-language-in-chinese/chapter1/01_swift.html 有时间再看,bas ...

  5. nginx面试题

    1.Nginx是如何实现高并发的 service nginx start之后,然后输入#ps -ef|grep nginx,会发现Nginx有一个master进程和若干个worker进程,这些work ...

  6. altium designer 13 学习之添加汉字

    在altium desginer中如果你是想添加英文还是比较方便的,基本直接就可以输入了,但是添加中文就不是那么简单了,下面不介绍下如何在altium designer中快速的添加自己想要的中文 工具 ...

  7. 将 Qt 5.6 集成至 VS2015

    摘要: 由于VS2015不再支持addin,所以要用其他手段. 这里给出64位系统下的安装步骤,32位类似. 一.安装VS2015 过程略.值得注意的是要选择需要安装的内容,既然要用Qt,那么C++相 ...

  8. Android:控件ListView列表项与适配器结合使用

    Listview是用来展示一些重复性的数据用的,比如一些列表集合数据展示到手机,需要适配器作为载体获取数据,最后将数据填充到布局. ListView里面的每个子项Item可以使一个字符串,也可以是一个 ...

  9. POJ 2255 Tree Recovery 二叉树的遍历

    前序和中序输入二叉树,后序输出二叉树:核心思想只有一个,前序的每个根都把中序分成了两部分,例如 DBACEGF ABCDEFG D把中序遍历的结果分成了ABC和EFG两部分,实际上,这就是D这个根的左 ...

  10. Eclipse反编译工具Jad及插件JadClipse配置(转)

    Eclipse反编译工具Jad及插件JadClipse配置 Jad是一个Java的一个反编译工具,是用命令行执行,和通常JDK自带的java,javac命令是一样的.不过因为是控制台运行,所以用起来不 ...