Mark duplicate features in attribute table with Field Calculator, update to Arc10

2476
13
09-05-2011 06:39 PM
ChrisWoodward1
New Contributor III
I've got a handy piece of VB script that I used to routinely run on Arc9.3 to mark duplicate features in an attribute table based upon unique ID's in the table.  I typically use this on repeat points that appear within a dataset more than once (based upon ID value, Date/Time and position).  The problem is, the script won't work in Arc10 and I wasn't the original author so I'm not sure how to update it. 

I'm running Arc10 SP2 on a Windows 7 and/or XP machine.  My typical workflow is to concatenate a unique ID 'Unique_ID' (text, 255) based upon several attributes (say ID, Date/Time, Lat./Long).  I then create a attribute called 'dup' of a short interger type.  I run the field calculator on the dup field and load the following script and what it would normally do is to mark duplicate values of the Unique_ID value with a 1 value.  Both records wouldn't be marked, only the second or greater duplicate Unique_ID value record. 

Within the field calculator, I'd have the "Show Codeblock" checked and the following in the "Pre-Logic Script Code" area:

Static d As Object
Static i As Long
Dim iDup As Integer
Dim sField
'========================
'Replace the field name bellow
sField = [Chris_ID]
'========================
If (i = 0) Then
  Set d = CreateObject("Scripting.Dictionary")
End If
If (d.Exists(CStr(sField))) Then
  iDup = 1
Else
  d.Add CStr(sField), 1
  iDup = 0
End If
i = i + 1

The following would also be in the bottom part: Dup=iDup

If someone could help me with updating this VB script for Arc10, it would be greatly appreciated!

Thanks,
Chris
Tags (2)
0 Kudos
13 Replies
ChrisGraves
Occasional Contributor
Hey GIS Users,

I'm trying to identify duplicate records from a field and then change these fields so they become unique (eg A,B,C, or 1,2,3) and assign this to the end of the text (eg F3241 A56_A or F3241 A56_1).
I've tried the scripts that are in this forum but can't get these to work or not sure if they will give me the result I'm after.
Any input into to this would be greatly appreciated.

Cheers,

Chris
0 Kudos
shivamparashari
New Contributor
Hi,

Actually, I was working with Address Points and had to calculate Spatial Duplicates(same X & Y Coordinates) and Address Duplicates(same attributes). gnewburyiv gave the idea and it worked. Gracias. Now, for address duplicates, I need to check for more than two fields(valX, valY, valZ, valA, valB etc.). What can be done in this case. (:
0 Kudos
RobBlash
Occasional Contributor III
The old "find duplicates" code I was using at 9.x was ported as an addin, thanks to whomever did this work.

http://www.arcgis.com/home/item.html?id=2f8c0a2477db465b8ca2a9f7f519eb5a

It works great to find attribute duplicates and doesn't require new fields, editing, info license etc.



Hi,

Actually, I was working with Address Points and had to calculate Spatial Duplicates(same X & Y Coordinates) and Address Duplicates(same attributes). gnewburyiv gave the idea and it worked. Gracias. Now, for address duplicates, I need to check for more than two fields(valX, valY, valZ, valA, valB etc.). What can be done in this case. (:


To find duplicates amongst many fields you can concatenate the values into one field and then check with the tool I linked above. If you're looking for spatial duplicates in points try using the point distance in toolbox (I think you need an editor or an info license)
0 Kudos
shivamparashari
New Contributor
Hi rblash Thanks for the reply. Actually, I am working  with ArcGIS 10.0, so the add-in is not working.
I did this thing in Python-

pre-logic script code:

def find_duplicates (valA , valB , valC , valD , valE , valF , valG):
d[( valA , valB , valC , valD , valE , valF , valG)] = d.setdefault ( ( valA , valB , valC , valD , valE , valF , valG) , -1) +1
return d[ ( valA , valB , valC , valD , valE , valF , valG) ]


ObjectID:

find_duplicates ( !hnr1! , !pc_main! , !city! , !attribdate! , !geocodinga! , !AdminPlace! , !Building_9! )
(:
0 Kudos