风过无痕 原文 arcengine,深入理解游标Cursors,实现数据的快速查找,插入,删除,更新
深入理解游标Cursors,实现数据的快速查找,插入,删除,更新
1、查找数据Search Cursors
//by yl landgis@126.com yanleigis@21cn.com 2008.7.7
IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(508786, 681196, 513033, 684341); 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);//只查询,true快一些 IFeature feature = searchCursor.NextFeature(); int n = 0; while (feature != null){ n++; feature = baseCursor.NextFeature(); }
2、插入数据Insert Cursors—目前数据插入最快的方法
//by yl landgis@126.com yanleigis@21cn.com 2008.7.7
IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); IFeatureCursor featureCursor = featureClass.Insert(true); object featureOID; featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "B Pierce"); for (int ic = 0; ic < 99; ic++) { featureBuffer.Shape = geometry featureOID = featureCursor.InsertFeature(featureBuffer); } featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "K Johnston"); for (int ic = 0; ic < 99; ic++) { featureBuffer.Shape = geometry featureOID = featureCursor.InsertFeature(featureBuffer); } featureCursor.Flush();
3、 数据删除 delete
//by yl landgis@126.com yanleigis@21cn.com 2008.7.7
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 = 0; while (feature != null) { m++; updateCursor.DeleteFeature(feature); feature = updateCursor.NextFeature(); }
4、数据更新 update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
//by yl landgis@126.com yanleigis@21cn.com 2008.7.7
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(
"Parcels"
);
// restrict the number of features to be updated.
IQueryFilter queryFilter =
new
QueryFilterClass();
queryFilter.WhereClause =
"ZONING_S = 'U'"
;
// use IFeatureClass::Update to populate IFeatureCursor
IFeatureCursor updateCursor = featureClass.Update(queryFilter,
false
);
int
fieldindex = featureClass.FindField(
"ZONING_S"
);
IFeature feature = updateCursor.NextFeature();
int
m = 0;
while
(feature !=
null
)
{
m++;
feature.set_Value(fieldindex,
"X"
);
updateCursor.UpdateFeature(feature);
feature = updateCursor.NextFeature();
}
|
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/6114330.html
,如需转载请自行联系原作者