深入理解游标Cursors,实现数据的快速查找,插入,删除,更新(转)

本文主要是介绍深入理解游标Cursors,实现数据的快速查找,插入,删除,更新(转),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

深入理解游标Cursors,实现数据的快速查找,插入,删除,更新

1、         查找数据Search Cursors  //by yl landgis@126.com  yanleigis@21cn.com 2008.7.7

 [C#]

//Create an envelope for the lower right portion of data

IEnvelope envelope = new EnvelopeClass();

envelope.PutCoords(508786, 681196, 513033, 684341);

 

// create a spatial query filter

ISpatialFilter spatialFilter = new SpatialFilterClass();

 

// specify the geometry to query with

spatialFilter.Geometry = envelope;

 

// specify what the geometry field is called on the Feature Class that we will querying against

String shpFld = featureClass.ShapeFieldName;

spatialFilter.GeometryField = shpFld;

 

// specify the type of spatial operation to use

spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

// perform the query and use a cursor to hold the results

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

//Create the Feature Buffer
IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
 
//Create insert feature cursor using buffering = true.
IFeatureCursor featureCursor = featureClass.Insert(true);
 
object featureOID;       
 
//All of the features to be created were installed by "B Pierce"
featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "B Pierce");
for (int ic = 0; ic < 99; ic++) 
{
    
    //Set the featurebuffers's shape
    featureBuffer.Shape = geometry
    
    //Insert the feature into the feature cursor
    featureOID = featureCursor.InsertFeature(featureBuffer);
}
 
//All of the features to be created were installed by "K Johnston"
featureBuffer.set_Value(featureBuffer.Fields.FindField("InstBy"), "K Johnston");
for (int ic = 0; ic < 99; ic++)
{
    //Set the feature's shape
    featureBuffer.Shape = geometry
 
    //Insert the feature into the feature cursor
    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'";

 

// use IFeatureClass::Update to populate IFeatureCursor

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   //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();

}

这篇关于深入理解游标Cursors,实现数据的快速查找,插入,删除,更新(转)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/476992

相关文章

Spring 请求之传递 JSON 数据的操作方法

《Spring请求之传递JSON数据的操作方法》JSON就是一种数据格式,有自己的格式和语法,使用文本表示一个对象或数组的信息,因此JSON本质是字符串,主要负责在不同的语言中数据传递和交换,这... 目录jsON 概念JSON 语法JSON 的语法JSON 的两种结构JSON 字符串和 Java 对象互转

python实现svg图片转换为png和gif

《python实现svg图片转换为png和gif》这篇文章主要为大家详细介绍了python如何实现将svg图片格式转换为png和gif,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录python实现svg图片转换为png和gifpython实现图片格式之间的相互转换延展:基于Py

Python利用ElementTree实现快速解析XML文件

《Python利用ElementTree实现快速解析XML文件》ElementTree是Python标准库的一部分,而且是Python标准库中用于解析和操作XML数据的模块,下面小编就来和大家详细讲讲... 目录一、XML文件解析到底有多重要二、ElementTree快速入门1. 加载XML的两种方式2.

Java的栈与队列实现代码解析

《Java的栈与队列实现代码解析》栈是常见的线性数据结构,栈的特点是以先进后出的形式,后进先出,先进后出,分为栈底和栈顶,栈应用于内存的分配,表达式求值,存储临时的数据和方法的调用等,本文给大家介绍J... 目录栈的概念(Stack)栈的实现代码队列(Queue)模拟实现队列(双链表实现)循环队列(循环数组

redis过期key的删除策略介绍

《redis过期key的删除策略介绍》:本文主要介绍redis过期key的删除策略,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录第一种策略:被动删除第二种策略:定期删除第三种策略:强制删除关于big key的清理UNLINK命令FLUSHALL/FLUSHDB命

C++如何通过Qt反射机制实现数据类序列化

《C++如何通过Qt反射机制实现数据类序列化》在C++工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作,所以本文就来聊聊C++如何通过Qt反射机制实现数据类序列化吧... 目录设计预期设计思路代码实现使用方法在 C++ 工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作。由于数据类

Python实现图片分割的多种方法总结

《Python实现图片分割的多种方法总结》图片分割是图像处理中的一个重要任务,它的目标是将图像划分为多个区域或者对象,本文为大家整理了一些常用的分割方法,大家可以根据需求自行选择... 目录1. 基于传统图像处理的分割方法(1) 使用固定阈值分割图片(2) 自适应阈值分割(3) 使用图像边缘检测分割(4)

Android实现在线预览office文档的示例详解

《Android实现在线预览office文档的示例详解》在移动端展示在线Office文档(如Word、Excel、PPT)是一项常见需求,这篇文章为大家重点介绍了两种方案的实现方法,希望对大家有一定的... 目录一、项目概述二、相关技术知识三、实现思路3.1 方案一:WebView + Office Onl

C# foreach 循环中获取索引的实现方式

《C#foreach循环中获取索引的实现方式》:本文主要介绍C#foreach循环中获取索引的实现方式,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、手动维护索引变量二、LINQ Select + 元组解构三、扩展方法封装索引四、使用 for 循环替代

Spring Security+JWT如何实现前后端分离权限控制

《SpringSecurity+JWT如何实现前后端分离权限控制》本篇将手把手教你用SpringSecurity+JWT搭建一套完整的登录认证与权限控制体系,具有很好的参考价值,希望对大家... 目录Spring Security+JWT实现前后端分离权限控制实战一、为什么要用 JWT?二、JWT 基本结构