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


    原文地址:http://www.cnblogs.com/caodajieup/archive/2011/11/02/2232658.html

    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 = 0;

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

     

     

    2、 插入数据

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

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

     IFeature newLineFeature = LineFeaClass.CreateFeature();                           

    newLineFeature.Shape = pFeature.Shape;
    int ii = newLineFeature.Fields.FindField(AreaZonalName); 

     if (ii > 0)                           

    {                               

    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 

    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 

    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 = 0;

    while (feature != null)

    {

        m++;

        feature.set_Value(fieldindex, "X");

        updateCursor.UpdateFeature(feature);

        feature = updateCursor.NextFeature();

    }

  • 相关阅读:
    原生js中,call(),apply(),bind()三种方法的区别
    jQuery回溯!!!!!!!
    java中异常类与类别
    Java 多线程(并发)
    Java中反射与常用方法
    漫谈计算机构成
    java语言特性(相比C++)
    初级排序算法学习笔记
    java中参数传递
    关于类的知识
  • 原文地址:https://www.cnblogs.com/CSharpLover/p/5783908.html
Copyright © 2020-2023  润新知