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