Randomly select points in a feature layer

450
2
06-09-2022 03:40 AM
MVAC
by
New Contributor III

Hello,

I have a feature layer (points). So, I'd like to randomly select several points based on the value in one of the columns ('level_' column).

For instance, I'd like to randomly select 16 points of level 1 and 10 of level 2, then I will use the result to plan a route using plan_routes().   The thing is that I don't want the two results separate because I need them to be in the same feature so I can use them as input for planning the routes.

In the code below I queried the feature layer to get only the points of level 1 & 2.

# query parcels - level 1 & 2
m_levels = test.query(where="level_= '1' OR level_='2'")
m_levels

 

Thanks!

Tags (2)
0 Kudos
2 Replies
DavidAnderson_1701
Occasional Contributor

The Python random package does what you ask. The function random.sample for sampling without replacement and random.choices for sampling with replacement.

Then all you have to do is get the data into Python.  In arcpy there is FeatureClassToNumPyArray  In the Arcgis API there is the spatially enabled dataframe https://developers.arcgis.com/python/guide/introduction-to-the-spatially-enabled-dataframe/#:~:text=....

 

MVAC
by
New Contributor III

Thanks!

0 Kudos