Info on parallel processing in Python - good potential for GIS users!
A space for discussions and research in the area of Geographic Information Science and Technology (GIST).
Showing posts with label arcpy. Show all posts
Showing posts with label arcpy. Show all posts
Sunday, 16 March 2014
Wednesday, 15 February 2012
Arcpy Code: Find duplicate values in an ArcGIS feature class field
I'm finding coding in arcpy a little more frustrating than I would like and decided to share useful code here in case it helps anyone else trying to the same or similar things.
###########################################
# identifyduplicates.py
# Created by: Mairead de Roiste, Victoria University of Wellington
# Date: 16 Feb 2012
# What does it do?: prints to screen a list of the values that are
# duplicates in a particular field in an ArcGIS feature class
###########################################
# Import arcpy module
import arcpy
# set up variables
# the feature class you want to sort then search
fc = "D:\\ISCR_transport\\code\\data\\NZTA_workhomepoints\\workhomepoints.gdb\\workloc"
# field to sort in ascending order
fieldname = "FIRST_uniquePerson"fieldascend = fieldname + " A"
# create UpdateCursor to search through the rows, field above sorted in ascending order
rows = arcpy.SearchCursor(fc,"","","", fieldascend)
#Create an empty list
dupValuesList = []
# the code needs to be updated for the name of the field
i = -1
for row in rows:
if i == -1: #first time around
value = row.FIRST_uniquePerson
i += 1
print value, i
elif row.FIRST_uniquePerson != value: #if a new ID
value = row.FIRST_uniquePerson
i = 0
else:
dupValuesList.append(value)
print dupValuesList
###########################################
# identifyduplicates.py
# Created by: Mairead de Roiste, Victoria University of Wellington
# Date: 16 Feb 2012
# What does it do?: prints to screen a list of the values that are
# duplicates in a particular field in an ArcGIS feature class
###########################################
# Import arcpy module
import arcpy
# set up variables
# the feature class you want to sort then search
fc = "D:\\ISCR_transport\\code\\data\\NZTA_workhomepoints\\workhomepoints.gdb\\workloc"
# field to sort in ascending order
fieldname = "FIRST_uniquePerson"fieldascend = fieldname + " A"
# create UpdateCursor to search through the rows, field above sorted in ascending order
rows = arcpy.SearchCursor(fc,"","","", fieldascend)
#Create an empty list
dupValuesList = []
# the code needs to be updated for the name of the field
i = -1
for row in rows:
if i == -1: #first time around
value = row.FIRST_uniquePerson
i += 1
print value, i
elif row.FIRST_uniquePerson != value: #if a new ID
value = row.FIRST_uniquePerson
i = 0
else:
dupValuesList.append(value)
print dupValuesList
Subscribe to:
Posts (Atom)