深入理解游标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

相关文章

SpringBoot全局域名替换的实现

《SpringBoot全局域名替换的实现》本文主要介绍了SpringBoot全局域名替换的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录 项目结构⚙️ 配置文件application.yml️ 配置类AppProperties.Ja

Python实现批量CSV转Excel的高性能处理方案

《Python实现批量CSV转Excel的高性能处理方案》在日常办公中,我们经常需要将CSV格式的数据转换为Excel文件,本文将介绍一个基于Python的高性能解决方案,感兴趣的小伙伴可以跟随小编一... 目录一、场景需求二、技术方案三、核心代码四、批量处理方案五、性能优化六、使用示例完整代码七、小结一、

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

C#实现一键批量合并PDF文档

《C#实现一键批量合并PDF文档》这篇文章主要为大家详细介绍了如何使用C#实现一键批量合并PDF文档功能,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言效果展示功能实现1、添加文件2、文件分组(书签)3、定义页码范围4、自定义显示5、定义页面尺寸6、PDF批量合并7、其他方法

SpringBoot实现不同接口指定上传文件大小的具体步骤

《SpringBoot实现不同接口指定上传文件大小的具体步骤》:本文主要介绍在SpringBoot中通过自定义注解、AOP拦截和配置文件实现不同接口上传文件大小限制的方法,强调需设置全局阈值远大于... 目录一  springboot实现不同接口指定文件大小1.1 思路说明1.2 工程启动说明二 具体实施2

Python实现精确小数计算的完全指南

《Python实现精确小数计算的完全指南》在金融计算、科学实验和工程领域,浮点数精度问题一直是开发者面临的重大挑战,本文将深入解析Python精确小数计算技术体系,感兴趣的小伙伴可以了解一下... 目录引言:小数精度问题的核心挑战一、浮点数精度问题分析1.1 浮点数精度陷阱1.2 浮点数误差来源二、基础解决

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

Java实现远程执行Shell指令

《Java实现远程执行Shell指令》文章介绍使用JSch在SpringBoot项目中实现远程Shell操作,涵盖环境配置、依赖引入及工具类编写,详解分号和双与号执行多指令的区别... 目录软硬件环境说明编写执行Shell指令的工具类总结jsch(Java Secure Channel)是SSH2的一个纯J

使用Python实现Word文档的自动化对比方案

《使用Python实现Word文档的自动化对比方案》我们经常需要比较两个Word文档的版本差异,无论是合同修订、论文修改还是代码文档更新,人工比对不仅效率低下,还容易遗漏关键改动,下面通过一个实际案例... 目录引言一、使用python-docx库解析文档结构二、使用difflib进行差异比对三、高级对比方