zoukankan      html  css  js  c++  java
  • ArcEngine数据删除几种方法和性能比较

    转自原文 ArcEngine数据删除几种方法和性能比较

    一、  几种删除方法代码

    1.  查询结果中删除

    private void Delete1(IFeatureClass PFeatureclass)

    {

    IQueryFilter pQueryFilter = new QueryFilterClass();

    pQueryFilter.WhereClause = "objectID<=" + DeleteNum;

    IFeatureCursor pFeatureCursor = PFeatureclass.Search(pQueryFilter, false);IFeature pFeature = pFeatureCursor.NextFeature();

    while (pFeature != null)

    {

      pFeature.Delete();

      pFeature = pFeatureCursor.NextFeature();

    }

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);

    }

    2.  更新游标删除

    private void Delete2(IFeatureClass PFeatureclass)

    {

    IQueryFilter pQueryFilter = new QueryFilterClass();

    pQueryFilter.WhereClause = "objectID<=" + DeleteNum;

    IFeatureCursor pFeatureCursor = PFeatureclass.Update(pQueryFilter, false);

    IFeature pFeature = pFeatureCursor.NextFeature();

    while (pFeature != null)

    {

      pFeatureCursor.DeleteFeature();

      pFeature = pFeatureCursor.NextFeature();

    }

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);

    }

    3.  使用DeleteSearchedRows删除

    private void Delete4(IFeatureClass PFeatureclass)

    {

    IQueryFilter pQueryFilter = new QueryFilterClass();

    pQueryFilter.WhereClause = "objectID<=" + DeleteNum;

    ITable pTable = PFeatureclass as ITable;

    pTable.DeleteSearchedRows(pQueryFilter);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);

    }

     

    4.  ExecuteSQL删除

    private void Delete4(IFeatureClass PFeatureclass)

    {

    IDataset pDataset = PFeatureclass as IDataset;

    pDataset.Workspace.ExecuteSQL("delete from " + PFeatureclass.AliasName + " where objectid<=" + DeleteNum);

    }

    二、  测试性能和比较

    1 相同的数据条件,删除2000条记录

    2 测试代码

    IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;

    IFeatureClass PFeatureClass = pFeatureLayer.FeatureClass;

    System.Diagnostics.Stopwatch MyWatch = new System.Diagnostics.Stopwatch();

    MyWatch.Start();

    Delete1(PFeatureClass)

    //Delete2(PFeatureClass);

    //Delete3(PFeatureClass);

    //Delete4(PFeatureClass);

  • 相关阅读:
    Object之克隆对象clone 和__clone()函数
    Object之魔术函数__toString() 直接输出对象引用时自动调用
    Object之魔术函数__call() 处理错误调用
    Git关联远程GitHub仓库
    python制作查找单词翻译的脚本
    用python处理文本,本地文件系统以及使用数据库的知识基础
    基于序列化技术(Protobuf)的socket文件传输
    Python核心编程——Chapter16
    gdb初步窥探
    unp学习笔记——Chapter1
  • 原文地址:https://www.cnblogs.com/arxive/p/6110155.html
Copyright © 2011-2022 走看看