Skip to content

Instantly share code, notes, and snippets.

@maptastik
Last active November 26, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptastik/f8a01ea054df1210ec03f657b9f5cba4 to your computer and use it in GitHub Desktop.
Save maptastik/f8a01ea054df1210ec03f657b9f5cba4 to your computer and use it in GitHub Desktop.
Create a random sample from a dataset based on OBJECTID...not perfect, but a good start!
import arcpy
import numpy as np
def randomFCSample(fc, fd='sample_fd', sample_field='OBJECTID', sample_pct=10):
count_class = arcpy.GetCount_management(fc)
count = int(count_class[0])
random_vals = np.random.choice(count, int(count*(sample_pct/100)))
arcpy.MakeFeatureLayer_management(fc,
fd + "_" + str(sample_pct) + 'pct',
sample_field + ' IN ' + str(tuple(random_vals)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment