# Select Random Point Based on Proximity of Other Points [closed]

I want to randomly select 50 points from a point layer of 3,000, but no two points can be within 100 miles of each other. Having difficulty moving beyond a theoretical framework into something practical. I have access to ArcGIS and QGIS, if one or the other's better suited for this. I also know some python but haven't figured out what to do.

• Duplicate, at least in the algorithm if not the language, of gis.stackexchange.com/questions/299625/… Commented Oct 22, 2018 at 20:36
• What do you mean by "randomly"? The only sense I can make of "randomly" here is to select with uniform probability one of the M possible subsets from N that satisfy your distance constraint. If you don't care about that, then what you really want is a set of any 50 points that satisfy your condition. Commented Oct 22, 2018 at 20:39
• Please decide which of ArcGIS Desktop, QGIS and Python you wish to ask about in this particular question. That way you can tell us what you have tried and where you are stuck.
– PolyGeo
Commented Oct 22, 2018 at 22:27

You can achieve this with one tool if you have an advance level license in ArcMap. No need for any code or complex modelling and looping.

1. Create your point layer with 3,000 points
2. Run the Create Random Points tool. The trick here is to set the constraining featureclass to be your 3,000 point layer, set number of points to 50 and minimum allowed distance to 100 miles.

The output will have a CID field which you can use to join any attribution from your 3,000 points layer or if you wish use your new layer to select from the 3,000 layer.

The very loose theoretical workflow that I could see being useful for this is:

1. Get the ObjectID or other unique identifier for all of the features and store them, maybe in a python list of all features to choose randomly from. (In arcpy I would do this with a search cursor)
2. Choose a random item from the list, using python's random module (https://docs.python.org/2/library/random.html#random.choice) and save that unique identifier to a new list (this will be your output list of random points). Remove that unique ID from the list of all features' unique IDs.
3. Select all of the points within 100 miles of this first chosen random point, get their unique IDs, and remove these ID's from the list of all features to choose from. (In ArcGIS I would likely do this with select by location, then a search cursor on the selected features)
4. Repeat step 2 & 3 until you have 50 feature's unique IDs in your second list. Each iteration would progressively shrink the list of features to choose from, ensuring you don't get a feature within the specified distance.
5. Use the new list of 50 feature unique ID's to select the features you are wanting, and presumably export the selected set? (In ArcGIS I would do this with Select by Attribute)

Note: this workflow assumes you have enough features, dispersed enough, that you can select the points randomly. Depending on your input dataset, if most of your points are densely clustered, there may not be enough points left by the end to select all 50 points.

If any of that isn't clear, let me know and I will try and clarify.

An algorithm for this can be implemented in Python:

1. Instantiate an empty RTree.