• 删除重复的feature vba VS 删除重复的feature python


    VBA:

     1 Sub deleteDuplicatedFeature()
     2 
     3 Dim app As IApplication
     4 Set app = Application
     5 
     6 Dim pMxDocument As IMxDocument
     7 Set pMxDocument = Application.Document
     8 
     9 Dim pMap As IMap
    10 Set pMap = pMxDocument.FocusMap
    11 
    12 Dim pFeatureLayer As IFeatureLayer
    13 Set pFeatureLayer = pMap.Layer(0)
    14 
    15 
    16 Dim pFeatureClass As IFeatureClass
    17 Set pFeatureClass = pFeatureLayer.FeatureClass
    18 
    19 
    20 Dim pFeatureCursor As IFeatureCursor
    21 Set pFeatureCursor = pFeatureClass.Search(Nothing, False)
    22 
    23 Dim pArea As IArea
    24 Dim pRelOp As IRelationalOperator
    25 Dim pFeature As IFeature
    26 Set pFeature = pFeatureCursor.NextFeature
    27 
    28 Dim findex As Integer
    29 findex = pFeatureClass.FindField("ifCopyed")
    30 
    31 Dim fid As Integer
    32 fid = pFeatureClass.FindField("FID")
    33 
    34 
    35 Dim pFilter As ISpatialFilter
    36 
    37 Dim pFeatureCursorCompared As IFeatureCursor
    38 Dim pFeatureCompared As IFeature
    39 Dim pShapeCompared As IPolygon
    40 Dim pAreaCompared As IArea
    41 
    42  
    43 
    44 While Not pFeature Is Nothing
    45    
    46    Set pRelOp = pFeature.Shape
    47 
    48    
    49    Set pFilter = New SpatialFilter
    50 
    51    With pFilter
    52     Set .Geometry = pFeature.Shape
    53         .GeometryField = "SHAPE"
    54         .SpatialRel = esriSpatialRelIntersects
    55    End With
    56   
    57    Set pFeatureCursorCompared = pFeatureClass.Search(pFilter, False)
    58    Set pFeatureCompared = pFeatureCursorCompared.NextFeature
    59 
    60 
    61    
    62    
    63     While Not pFeatureCompared Is Nothing
    64     
    65         Set pShapeCompared = pFeatureCompared.Shape
    66         
    67         If pRelOp.Equals(pShapeCompared) And pFeature.Value(fid) <> pFeatureCompared.Value(fid) Then
    68     
    69             pFeatureCompared.Delete   '删除之后,查询可以可以自动调节
    70             
    71          End If
    72    
    73 
    74          
    75          Set pFeatureCompared = pFeatureCursorCompared.NextFeature
    76     Wend
    77 
    78    Set pFeature = pFeatureCursor.NextFeature
    79 Wend

    Python:

    #run this program at arcgis10.0 environment please

     1 import arcpy
     2 
     3 fc = "D:Output.shp"  #change to your own shapefile
     4 
     5 desc = arcpy.Describe(fc)
     6 
     7 shapefieldname = desc.ShapeFieldName
     8 
     9 rows = arcpy.SearchCursor(fc)
    10 
    11 for row in rows:
    12     rows2 = arcpy.UpdateCursor(fc) 
    13     for row2 in rows2:
    14         if row.getValue(shapefieldname).equals(row2.getValue(shapefieldname)) and row.getValue("FID") != row2.getValue ("FID"):
    15             rows2.deleteRow(row2)
    16     del row2       
    17 
    18 del rows

    区别:

    1 vba繁琐,python简洁

    2 vba要用到接口跳转,python没有接口概念,只有类或者函数

    3 vba使用变量要先声明,python直接使用,不用声明

    4 vba在arcgis10以后不支持了,python会被支持,而且python用途非常之广

    5 vba和arcengine中思路非常类似,python开辟了一些新的思路,就像当初接触arcserver javascript api带来的新思路一样

    6 vba可以继续使用,大力使用python

    7 vba中缩进没有含义,python中缩进具有语法含义

    8 vba中的循环和判断语句有开头和结尾(for......end,if......end),python中循环和判断语句有冒号(:)

    文章来源:http://www.cnblogs.com/zhangjun1130/archive/2012/10/16/2726000.html

  • 相关阅读:
    springclould feign客户端添加全局参数
    mysql单向自动同步
    MongoDB的安装和配置(Windows系统)及遇到的常见问题解答
    电脑中安装多个jdk,eclipse的选择!
    css(外部样式表)中各种选择器(定义属性时)的优先级
    HTML5结合CSS的三种方法+结合JS的三种方法
    HTML5图片居中的问题
    html->html5->css->javascript(js)->jQuery->AJAX->JSON
    自定义方法实现ArrayList排序
    java,while循环的使用,接收用户的输入,进行不同的操作!
  • 原文地址:https://www.cnblogs.com/qiernonstop/p/3634358.html
Copyright © 2020-2023  润新知