重複資料刪除的feature vba VS 重複資料刪除的feature python

來源:互聯網
上載者:User

Sub deleteDuplicatedFeature()

Dim app As IApplication
Set app = Application

Dim pMxDocument As IMxDocument
Set pMxDocument = Application.Document

Dim pMap As IMap
Set pMap = pMxDocument.FocusMap

Dim pFeatureLayer As IFeatureLayer
Set pFeatureLayer = pMap.Layer(0)

Dim pFeatureClass As IFeatureClass
Set pFeatureClass = pFeatureLayer.FeatureClass

Dim pFeatureCursor As IFeatureCursor
Set pFeatureCursor = pFeatureClass.Search(Nothing, False)

Dim pArea As IArea
Dim pRelOp As IRelationalOperator
Dim pFeature As IFeature
Set pFeature = pFeatureCursor.NextFeature

Dim findex As Integer
findex = pFeatureClass.FindField("ifCopyed")

Dim fid As Integer
fid = pFeatureClass.FindField("FID")

Dim pFilter As ISpatialFilter

Dim pFeatureCursorCompared As IFeatureCursor
Dim pFeatureCompared As IFeature
Dim pShapeCompared As IPolygon
Dim pAreaCompared As IArea

 

While Not pFeature Is Nothing
  
   Set pRelOp = pFeature.Shape

  
   Set pFilter = New SpatialFilter

   With pFilter
    Set .Geometry = pFeature.Shape
        .GeometryField = "SHAPE"
        .SpatialRel = esriSpatialRelIntersects
   End With
 
   Set pFeatureCursorCompared = pFeatureClass.Search(pFilter, False)
   Set pFeatureCompared = pFeatureCursorCompared.NextFeature

  
  
    While Not pFeatureCompared Is Nothing
   
        Set pShapeCompared = pFeatureCompared.Shape
       
        If pRelOp.Equals(pShapeCompared) And pFeature.Value(fid) <> pFeatureCompared.Value(fid) Then
   
            pFeatureCompared.Delete   '刪除之後,查詢可以可以自動調節
           
         End If
   

        
         Set pFeatureCompared = pFeatureCursorCompared.NextFeature
    Wend

   Set pFeature = pFeatureCursor.NextFeature
Wend

 ————————————————————————————————————————————————————————————

#run this program at arcgis10.0 environment please

import arcpy

fc = "D:\zhangjun\Export_Output9.shp"  #change to your own shapefile

desc = arcpy.Describe(fc)

shapefieldname = desc.ShapeFieldName

rows = arcpy.SearchCursor(fc)

for row in rows:
    rows2 = arcpy.UpdateCursor(fc)
    for row2 in rows2:
        if row.getValue(shapefieldname).equals(row2.getValue(shapefieldname)) and row.getValue("FID") != row2.getValue ("FID"):
            rows2.deleteRow(row2)
    del row2       

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中迴圈和判斷語句有冒號(:)

 

 

End Sub

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.