Last active
November 26, 2018 14:02
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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