Select to view content in your preferred language

Merge Find Identical and Update Cursor

795
0
10-22-2013 10:20 AM
ClintonCooper1
Deactivated User
As I am a newbie to python, I am trying to write the find identical feature Values into a new field in my current dataset.  I assume that I need to introduce the Update Cursor into the mix to get the desired result.  Below is my find identical script, and it is currently writing to another table.  Is there a way to consolidate it so I do not have to go through a whole other step that would include joining it & recalc/exporting the values back in back in?  I also have performance considerations in mind as I am working with 7+ million records, so if there is a better/faster way to do things I am very much open to it.  Here is my base code:


import arcpy

from itertools import groupby
from operator import itemgetter

# Find identical records based on a text field and a numeric field.
result =arcpy.FindIdentical_management(r"C:\Users\cc1\Desktop\temp\Metro_Bus_Stops.shp", r"C:\Users\cc1\Desktop\temp\duplicate_incidents.dbf", ["City", "STREET_SER"])
    
# List of all output records as IN_FID and FEAT_SEQ pair - a list of lists
out_records = []   
for row in arcpy.SearchCursor(result.getOutput(0), fields="IN_FID; FEAT_SEQ"):
    out_records.append([row.IN_FID, row.FEAT_SEQ])

# Sort the output records by FEAT_SEQ values
# Example of out_records = [[3, 1], [5, 3], [1, 1], [4, 3], [2, 2]]
out_records.sort(key = itemgetter(1))
    
# records after sorted by FEAT_SEQ: [[3, 1], [1, 1], [2, 2], [5, 3], [4, 3]]
# records with same FEAT_SEQ value will be in the same group (i.e., identical)
identicals_iter = groupby(out_records, itemgetter(1))
    
# now, make a list of identical groups - each group in a list.
# example identical groups: [[3, 1], [2], [5, 4]]
# i.e., IN_FID 3, 1 are identical, and 5, 4 are identical.
identical_groups = [[item[0] for item in data] for (key, data) in identicals_iter]
Tags (2)
0 Kudos
0 Replies