Guest User

Untitled

a guest
Aug 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import arcpy, random
  2. from collections import defaultdict
  3.  
  4. points = r'points' #Layer name
  5. groupfield = 'fishnet_id' #Some id identifying each fishnet cell spatially joined
  6. sample_size = 1 #Points to select per group
  7.  
  8. oidfield = arcpy.Describe(points).OIDFieldName
  9.  
  10. groups = defaultdict(list)
  11.  
  12. with arcpy.da.SearchCursor(points, [groupfield, oidfield]) as cursor:
  13. for key,value in cursor:
  14. groups[key].append(value)
  15.  
  16. oidlist = []
  17. for key,value in groups.items():
  18. oidlist.append(random.sample(value,sample_size)[0])
  19.  
  20. sql = """{0} IN({1})""".format(arcpy.AddFieldDelimiters(points,oidfield), ','.join([str(i) for i in oidlist]))
  21. arcpy.SelectLayerByAttribute_management(points, where_clause=sql)
Add Comment
Please, Sign In to add comment