Updated – 2/27/2015
Fixed compatibility with Python 3 for ArcGIS Pro
(If you’re using Firefox, then right click and Save Link As)
Download the Generate Random Points Toolbox – works with ArcGIS 10.1+
View the Source Code
(any donations go towards hosting costs)
Maybe you’re doing a soil analysis study (check out my Create Custom Grid tool) and need random locations for each sample? Or you’re doing a tree diversity study and need random locations where the number of tree species will be identified? Or maybe you’re just looking for an adventure and want to visit each random location created from a polygon around a city neighborhood? Who knows…
The Generate Random Points tool generates a number of random points inside each polygon of an input Polygon feature class. The number of random points can be a fixed number or based on a field.
An optional parameter can be set to define a minimum distance between the random points. There is also a parameter called Maximum Attempts, which is the maximum attempts the tool will make before failure. Depending on the number of random points and the minimum distance, there might not be a possible solution so the tool would run indefinitely.
If the maximum attempts for a polygon is reached, there are 3 choices on how to handle:
NO – The tool will fail and no random points will be generated.
KEEP_ALL – All generated random points will be returned. If one polygon could only generate 20 out of 100 random points, the 20 points will be included in the output.
KEEP_ONLY_SUCCESSFUL – Only polygons that succesfully generated all the required random points will have the random points included in the output.
The output Point feature class will contain a field called PolygonOID, which states the OID of the Polygon that each point was generated from.
Be sure to view the Tool Help within the tool dialog box for detailed instructions. Also, check the Geoprocessing Results for any error messages.
A similar ESRI tool called Create Random Points requires ArcInfo (Advanced) licensing.
This tool only requires ArcGIS 10.1 or later at any licensing level.
Here’s a screenshot of the parameters:
Here’s an example of generating 20 random points:
Here’s an example of generating 20 random points with a minimum distance of 200 feet:
I hope someone can find this tool useful. Please leave a comment if you have any questions or problems, and be sure to check out the other tools I’ve created!
I get the following error message. I am not a programmer so I am not sure how to fix this. I have numerous small polygons or clusters that I need to select a random number of these based on the size of the polygon.
Executing: GenerateRandomPoints MS4_CC_LynchBlksburg_091914 NO # 20 0 2000 NO C:\MichelleGISData\MS4_Annual2014\LynchBlkburg_1pctRandom_091914.shp
Start Time: Fri Sep 19 13:54:10 2014
Running script GenerateRandomPoints…
SyntaxError: invalid syntax (GenerateRandomPoints.tbx#GenerateRandomPoints_GenerateRandomPoints.py, line 1)
Failed to execute (GenerateRandomPoints).
Failed at Fri Sep 19 13:54:47 2014 (Elapsed Time: 37.00 seconds)
Michelle
Michelle- thanks for letting me know! It looks like I accidentally uploaded a bad copy of the toolbox. I’ve put up a new working copy.
This is a fantastic tool. Would be awesome to have it so that minimum distance is based on a field too
Hi Dean, thanks for the comment! That really wouldn’t be hard to do. If I get the time, I’ll try to add that capability!
Thanks Ian
Worked like a charm! Thanks so much!
Great, thanks for the comment!
Your scripts have come in incredibly handy. I really appreciate you making them available. It is especially helpful to have the scripts available to be able to learn just how they work in process. Thanks again!
Thanks, Luke!
Hey Ian, Great site and great tools. Just a little discussion point that I got thinking about while looking at this.
For the minimum distance setting “Keep_Successful”, does this just generate a random set of coords and then test if it is less than that minimum distance to another point? Inserting it if not and trying another random point again until the max number of tries?
It just feels like it lacks a bit of robustness if you get a lot less points than you wanted because you were unlucky with the ‘random’ part. You mention to lower the min distance or try more attempts but even keepin he same could result in different number of points.
As I write this I have a few ideas but none would be easily implemented or be perfect – using knowledge of the existing points locations, the max points that could fit in the polygon with the given min distance and statistical variance in the spread of the given number of points against the area and min distance.
Don’t mean to criticize, just wondered if you had any thoughts on it and if you tried anything more elaborate? The tool is great as is and for 99% of purposes wouldn’t need this functionality anyway. Purely academic.
That’s creepy. Where did the picture of me come from? I didn’t upload anything.
It’s from Gravatar. The email you used must have an account there.
Hi Ian,
Thanks another useful tool 🙂
Would you be able to add in an option to carry all the fields from the original polygon layer?
I’ve found another way to create points live within my SQL query. I haven’t figured out how to make it generate random points though.
Hi Naomi, thanks for the comment! I should be able to make that change sometime in the future. I’ve been busy lately, so I’m not sure when it will be. I’ll email you when I do.
Naomi, you can run a “Join” in sequence from that tool to accomplish what you want very easily.
Hi. The proposal of the tool is amazing. Perhaps, I have the follow message when I try to generate six points to my polygon: ‘Polygon’ object has no attribute ‘spatialReference’
Viewing the polygon properties and coordinate system of the shape, the spatial reference sounds ok. What should I do?
Hi Silvio, I’ve sent you an email to get more information.
Basic question. After I have downloaded the GenerateRandomPoints file.tbx, what next? Double clicking the file gives me a message that no program is associated with the file.
ArcGIS 10.3, Windows 7
Hello, I’ve sent you an email.
HI Ian,
How long does it generally take to generate 10 random points with a minimum distance of 500? I entered my parameters and started the random point generator, but it has been “generating” for over 30 minutes and it has made it to 0%. What might I be missing here? My polygon is a layer of a stream drainage. Thanks!
Hi John, creating only 10 points should be almost instant. There is definitely something wrong. I’ve sent you an email to get some more information.
Ian, thank you for this tool. I´m using it in replace from esri own tool, wich failed to place a number of points inside each feature reasonably close to the specified number, considering the minimum distance restriction.
I had some trouble using “PolygonOID” atribute gerenated by the script, when it failed to accomplish the join to double digit OIDs, but just when single digit OIDs were provided together with the double digit ones. Solved it running “Add field”+”Calculate Field” in sequence, just after points creation, to convert “PolygonOID” contents to “long” type.
It then worked smoothly, but got me in another problem. Since the number of points is now correctly much higher, i´m running into situations where points created inside different features don´t meet global minimum distance restriction, but only locally, inside each feature…
Can you give any advice in where or how to change your code to accomplish a global minimum distance restriction?
Thanks again.
thank you for this awesome tools!!
I have one question as same as Clueless.
After download, how to install or customized this tools in ARCGIS 10.2?
please let me know this!!