Advertisement
wtgeographer

Delete Duplicates

Sep 2nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1.  
  2. '''
  3. This script deletes identical rows in the mls point file.
  4.  
  5. Currently tested with 'apn' column which seemingly corresponds to unique listings.
  6. The column 'apn' was chosen because it provided both a handle on unique mls listing
  7. while also being a integer field making sorting easy. Sorting was necessary to identify duplicates
  8.  
  9. Additionally, many of the duplicate records contained refrence to the same property but were found 7-10 meters apart.
  10. This made the 'Delete Identical' tool (ArcGIS Advanced License only ) inadeqaute here.
  11.  
  12. Once duplicates were identified and removed geoprocessing tasks on the mls dataset for neighborhood determinations could be performed.
  13.  
  14. Author: Noah Huntington
  15. Date: 9/2/2017
  16.  
  17. '''
  18. import arcpy
  19.  
  20.  
  21.  
  22. arcpy.env.workspace = r'C:\Users\<user>\Desktop\opendoor\data.gdb'
  23. fc = 'mls'
  24.  
  25. fields = ['apn']
  26.  
  27. counter = 0
  28. matchCount = 0
  29. sql_clause = (None, 'ORDER BY apn ASC')
  30.  
  31. with arcpy.da.UpdateCursor(fc,'apn','','','', sql_clause) as cursor:
  32.  
  33.     for row in cursor:
  34.  
  35.         n = row[0]
  36.         if counter > 0 and oldN == n:
  37.             expression = "\"apn\" = {0}" .format(n)
  38.             if expression:
  39.                 #print 'We have a match!'
  40.                 cursor.deleteRow()
  41.                 matchCount = matchCount + 1
  42.  
  43.         oldN = n
  44.         counter = counter + 1
  45.  
  46. print matchCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement