1

Using ArcGIS, I have a large data set of occurrence data many of which are in similar places. I have created a fishnet around the total area and want to select a single random point from within each grid-square of the fishnet.

How do I go about this?

I want to run this multiple times so that I can then bootstrap it. I know I could subset each individual grid-square but there are approximately 100 of them so this would take a very long time.

  • Which ArcGIS version do you use? – BERA Aug 17 '18 at 16:29
  • @BERA I am using ArcMap 10.5.1 – Billy Gardener Aug 20 '18 at 9:32
3

You can use arcpy to randomly select points by some group attribute. In your case fishnet id.

First Intersect Points with fishnet to get a fishnet id attribute on all Points.

Then modify the commented lines and execute this in the Python window with the point layer added to the map:

import arcpy, random
from collections import defaultdict

points = 'points' #Layer name
groupfield = 'fishnet_id' #Some id identifying each fishnet cell
sample_size = 1 #Points to select per group

oidfield = arcpy.Describe(points).OIDFieldName

groups = defaultdict(list)

with arcpy.da.SearchCursor(points, [groupfield, oidfield]) as cursor:
    for key,value in cursor:
        groups[key].append(value)

oidlist = []
for key,value in groups.iteritems(): # use groups.items() for ArcGIS Pro/py3
    oidlist.extend(random.sample(value,sample_size))

sql = """{0} IN({1})""".format(arcpy.AddFieldDelimiters(points,oidfield), ','.join([str(i) for i in oidlist]))
arcpy.SelectLayerByAttribute_management(points, where_clause=sql)

enter image description here

  • 1
    Is there a way of doing this without the use of arcpy? – Billy Gardener Aug 20 '18 at 9:40
  • 1
    @BillyGardener probably, for example with ModelBuilder. But why not arcpy? – BERA Aug 20 '18 at 10:22
  • 1
    Not much experience using arcpy, I'm still trying to get with the basics of using it. – Billy Gardener Aug 20 '18 at 10:39
  • 1
    Ok! But my answer should not need much changing, only point layer name and group/fishnet field. I would recommend learning the da.Search/UpdateCursors. I use them Daily. – BERA Aug 20 '18 at 11:08
  • Hi, I was trying to implement the above. I have a raster layer (tiff) in 10m resolution and a lidar layer of several millions of point (about 200 points in each 10 m grid of my raster layer). How do I create a new point shapefile of the samples from my lidar point. Also, how can I manipulate my new point file such that it will give me 1 sample (mean value of all points in the 10 m grid) from each 10 m grid? – user18058 Aug 29 '18 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.