zoukankan      html  css  js  c++  java
  • 删除重复的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

  • 相关阅读:
    django序列化器Serializers
    django中模型类变更问题
    django图书管理系统-外键字段的增删改查
    django图书管理系统模型创建
    django中使用KindEditor上传图片
    成长
    git提交代码的经验
    react项目打包
    node——moudle
    git
  • 原文地址:https://www.cnblogs.com/qiernonstop/p/3634358.html
Copyright © 2011-2022 走看看