Hi to all,
I found a post from 2009 in the ArcObjects Visual Basic for Application (VBA) forum , the author is John Hauck.
He suggested the following code for finding duplicate geometry:
This code works fine for removing the duplicates but still gives an error, I am new into programming in general and also in Arcobjects. My question is:
Does anybody know how to debug it? or any other option to remove duplicated features using attributes.
Any help will be appreciated.
Thank you
Carlos Vázquez
I found a post from 2009 in the ArcObjects Visual Basic for Application (VBA) forum , the author is John Hauck.
He suggested the following code for finding duplicate geometry:
Code:
Sub DeleteDuplicates()
Dim pApp As IMxApplication
Dim pDoc As IMxDocument
Dim pFlayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Dim pCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pFeature1 As IFeature
Dim ii As Integer
Dim iFeatureCount As Integer
Dim pTableSort As ITableSort
Dim pTable As ITable
Dim pRelationalOperator As IRelationalOperator
Dim sFieldName As String
Dim iFieldIndex As Integer
Dim sFieldValue As String
Dim sFieldValue1 As String
Set pDoc = ThisDocument
Set pApp = Application
Set pFlayer = pDoc.FocusMap.Layer(1)
Set pFeatureClass = pFlayer.FeatureClass
iFeatureCount = pFeatureClass.FeatureCount(Nothing)
ii = 0
If pFeatureClass.ShapeType = esriGeometryPolyline Then
sFieldName = "SHAPE_Length"
iFieldIndex = pFeatureClass.FindField(sFieldName)
Debug.Print iFieldIndex
If iFieldIndex = -1 Then
MsgBox "No Field named: " & sFieldName & " in " & pFlayer.Name
Exit Sub
End If
End If
If pFeatureClass.ShapeType = esriGeometryPolygon Then
sFieldName = "SHAPE_Area"
iFieldIndex = pFeatureClass.FindField(sFieldName)
If iFieldIndex = -1 Then
MsgBox "No Field named: " & sFieldName & "in " & pFlayer.Name
Exit Sub
End If
End If
If pFeatureClass.ShapeType = esriGeometryPoint Then
MsgBox "Decide how you want to approach point layers"
End If
Set pTable = pFeatureClass
Set pTableSort = New TableSort
Set pTableSort.Table = pTable
pTableSort.Fields = sFieldName
pTableSort.Ascending(sFieldName) = True
pTableSort.Sort pApp.Display.CancelTracker
Set pCursor = pTableSort.Rows
Set pFeature = pCursor.NextFeature
ii = ii + 1
Do While ii <= iFeatureCount
sFieldValue = pFeature.value(iFieldIndex)
Debug.Print sFieldValue
ii = ii + 1
If ii <= iFeatureCount Then
Set pFeature1 = pCursor.NextFeature
sFieldValue1 = pFeature1.value(iFieldIndex)
Debug.Print sFieldValue1
If sFieldValue = sFieldValue1 Then
Set pRelationalOperator = pFeature.Shape
Debug.Print pFeature.Shape.IsEmpty
Debug.Print pFeature1.Shape.IsEmpty
If pRelationalOperator.Equals(pFeature1.Shape) Then
pFeature1.Delete
End If
Else
Set pFeature = pFeature1
End If
End If
Loop
Set pFcursor = Nothing
pDoc.ActivatedView.Refresh
End SubDoes anybody know how to debug it? or any other option to remove duplicated features using attributes.
Any help will be appreciated.
Thank you
Carlos Vázquez