I need to randomly select polygons from feature class...

04-09-2012 09:11 AM
New Contributor
I need to randomly select a specific number of polygons from a feature class and create a new feature class with the randomly generated polygons. Is there a way to do this?
0 Kudos
5 Replies
Esri Contributor

You may want to use Subset Features tool, provided you have Geostatisical Analyst extension.

also, please look the following forum post:


Hope this helps.

Thank you.
0 Kudos
New Contributor II
Before I migrated to ArcGIS 10 vesrion, i used very handy free tool (extension) Hawth's Analysis Tools for ArcGIS, and id had exactly tool that you need called
CREATE RANDOM SELECTION TOOL link: http://www.spatialecology.com/htools/rndsel.php
I used that for caclulation of DEM RMSE for my master thesis, and it worked perfectly ...
Unfortunately, tool is abandoned and there is no version for ArcGIS 10 😞
0 Kudos
New Contributor
Yes, I used Hawth's Tools previously but they changed to a new, less user friendly version called Geospatial Modelling environment that uses the Stats progrom R, etc.
0 Kudos
Occasional Contributor III
Use a search cursor to create a python list of your feature ids, and feed that list to
the python random module's random.choice(seq) function.
add the resulting selected feature id to a new list and remove that id the first list (so you don't pick it twice)
use alist.remove(x) to remove it from the first list
do these steps again and again untill you have the desired number of feature ids in the second list
make your feature selection on the feature ids that second list

Most of the stuff in Hawth's Tools is not hard to do outside the tool set, just a little tedious sometimes....
0 Kudos
New Contributor

Just ran into this same question, and ended up using the python random.sample function directly to create a subsequence of rows from the original search cursor, e.g.

all_addresses = [row.getValue("FID") for row in arcpy.SearchCursor("survey_master_address_list_2018", fields="FID")]
import random
sample_set = random.sample(all_addresses, sample_size)‍‍‍‍‍‍

I tried a few times to just use row objects directly and found that there were weird reference issues, so it works best to pull a list of FID values, sample those, and then you can loop back through the layer using an UpdateCursor and check for `row.FID in sample_set` to then perform operations on the sample.

0 Kudos