Select to view content in your preferred language

random selection of points outside of a minimum distance

4193
9
08-26-2010 08:29 AM
KumudanGrubh
Emerging Contributor
My question is the same as the one posted on http://forums.esri.com/thread.asp?t=194817&f=983&c=93 however, since I couldn't continue on that thread I'm posting a new one.

I would like to know how to randomly select a certain percentage of points from a point layer, and the selected points should at least have a minimum specified distance between them. Any help is greatly appreciated. Thanks.
0 Kudos
9 Replies
DrewFlater
Esri Regular Contributor
You can use the Create Random Points (management) tool to create a new feature class that contains random points that are "constrained" by your point layer. This will limit the location of the random points to existing point locations. This tool provides parameters for specifying a minimum distance as well as the number of random features you want to generate. If you wish for your input point layer to have a random selection, you can perform a Select By Location, where you select any of your input point features that intersect with one of the new random points.

The Create Random Points tool is available with an ArcInfo license, or with an ArcView or ArcEditor license if you have the Spatial Analyst of 3D Analyst extensions.

Here is the tool help page: Create Random Points (management)

Drew - ESRI
0 Kudos
ChrisSnyder
Honored Contributor
WARNING: The CreateRandomPoints tool has a fatal flaw!

Upon running the tool in a loop (for example, 30 loops and each loop creates 69 points each = 2070 points total), many of the "random" points are not spatially unique between loop iterations! In fact when I ran this tool as part of a Monte Carlo simulation, using 30 loops and 69 points each loop, only 483 of the 2070 points occur once! The other 1587 points were duplicated - up to 11 times!!! ^&%*&^% ^&%*&^%  ^&%*&^% !!! Now I have to rewrite my own script to create non-repeating pseudo-random points AND rerun my model (which takes two weeks to complete). Dang...

I reported this to ESRI last week, and the assigned it NIM060871 with a fix priority as "Low" - Go figure.

If you are interested, I am almost done with my own random point creation tool that mixes up the random number generator's "state" (and thus the derived point locations) using a single line of code (ESRI?):

random.jumpahead(int(time.time() * 100)) #probably more precise than necessary, but...

Anyway - beware of this tool if you plan to run it in a loop or even multiple times. The chance that you will get duplicate random points is extremely high.
0 Kudos
DrewFlater
Esri Regular Contributor
There are random number generator Seed and Random Generator Type environment settings that should help with this problem of getting repeated point locations. In ArcGIS 10.0, go to the Geoprocessing menu, Environments..., Random Numbers, to use those environment controls. The Create Random Points (management) help page that is linked to above has a section at the very bottom about which geoprocessing environments the tool uses. Follow the link about the Random Number generator environment to see more information.
0 Kudos
ChrisSnyder
Honored Contributor
Drew - thanks for the clarification.

From the v10 help:

If a tool using the random values (for example, Create Random Raster, Create Random Points, or Calculate Value) is run twice with the same seed, the output will be identical. Control over the seed allows you to reproduce your results.


The python code of my process is rooteed firmly in v9.3, but glad to hear there is a solution in v10 - Awesome!
0 Kudos
DrewFlater
Esri Regular Contributor
Chris, these same Random Number environments are also available in ArcGIS 9.3 and 9.3.1. In your Python script, set the environments using the code below.

import arcgisscripting
gp = arcgisscripting.create(9.3)

#set the random seed to 4, and the generator type to Mersenne Twister
gp.RandomGenerator = "4 MERSENNE_TWISTER"
0 Kudos
DanPatterson_Retired
MVP Emeritus
for other issues relating to random number generation see this thread
http://forums.arcgis.com/threads/5512-Creating-different-normal-rasters-within-each-entry-of-a-polyg...
0 Kudos
ChrisSnyder
Honored Contributor
Verified: Changing the random seed integer using gp.randomgenerator() does indeed solve the issue. I will however begrudgingly point out that the v9.3.1 help for the CreateRandomPoints tool (both the "built in" help and the "up-to-date" online help topic http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1783&pid=1777&topicname=Create_Random_Points_...), make absolutely no mention of the gp.randomgenerator() environment setting affecting the tool!

As of today (11/15/2010) the online v9.3.1 help topic states:

The following environment settings affect this tool: Workspace and scratch workspace.


No wonder both myself and the ESRI tech I reported the issue to missed it!

I should point out that the v10.0 help now correctly includes "Random number generator" as an environment setting that affects the CreateRandomPoint tool.
0 Kudos
DanPatterson_Retired
MVP Emeritus
which begs the question, that only esri can report on,....do previous versions of  the online help files get updated to correct errors, and/or provide amplifications AFTER a new version of ArcGIS is released, or are the non-migratory doomed to flawed/erroneous help?
0 Kudos
ChrisSnyder
Honored Contributor
In theory: the former...
In effect, the latter...
:rolleyes:
0 Kudos