Advertisement
wtgeographer

delete_dups

May 19th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 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 reference to the same parcel but were found 7-10 meters apart.
  10. This made the 'Delete Identical' tool (ArcGIS Advanced License and up ) inadequate here.
  11.  
  12. Once duplicates were removed, the MLS layer could be efficiently loaded in ArcMap.
  13.  
  14. '''
  15. import arcpy
  16. import time
  17. workspace = arcpy.env.workspace = r'C:\Users\noah\Desktop\gundog\chandler\data.gdb'
  18.  
  19. # city variable
  20. city = 'chandler'
  21.  
  22. def deleteDuplicates():
  23.     fc = 'mls'
  24.     fields = ['apn']
  25.  
  26.     counter = 0
  27.     matchCount = 0
  28.     sql_clause = (None, 'ORDER BY apn ASC')
  29.  
  30.     with arcpy.da.UpdateCursor(fc,'apn','','','', sql_clause) as cursor:
  31.  
  32.         for row in cursor:
  33.  
  34.             n = row[0]
  35.             if counter > 0 and oldN == n:
  36.                 expression = "\"apn\" = {0}" .format(n)
  37.                 if expression:
  38.                     #print 'We have a match!'
  39.                     cursor.deleteRow()
  40.                     matchCount = matchCount + 1
  41.  
  42.             oldN = n
  43.             counter = counter + 1
  44.  
  45.     print matchCount
  46.    
  47.  
  48. deleteDuplicates()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement