zoukankan      html  css  js  c++  java
  • 深入理解游标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 BufferIFeatureBuffer 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();

    }

     

     

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yanleigis/archive/2008/07/07/2620224.aspx

  • 相关阅读:
    【Navicat】查看历史执行的SQL
    什么是webpack模块化构建工具
    靠边的列表如果没有设置margin-left:20px,那么是看不到列表序号的。
    在博客园中复制代码到网页中,有时候会存在异常,如下:
    / WebAPP开发与小程序 / 步骤一 · 4-5 地图搜索与poi结合(2)
    忘记样式属性对应的值时,可以使用以下方法进行操作
    //点击按钮加减音频音量到最小会出现bug什么意思???
    组件化网页开发 3步骤 / 20门课
    position:absolute 按钮左右分布:left:0 和 right:0 以及雪碧图
    查看引入的文件是否成功
  • 原文地址:https://www.cnblogs.com/linghe/p/1635487.html
Copyright © 2011-2022 走看看