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