Created
December 18, 2018 14:28
-
-
Save maptastik/4e0be68d936a6d6531cdc85da8347181 to your computer and use it in GitHub Desktop.
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): | |
"""Return a randomish sample of a feature class as a feature layer | |
Parameters: | |
fc (str): Input feature class to sample | |
fd (str): Name of output feature layer | |
sample_field (int): Numeric field to sample values from | |
sample_pct (float): Percentage of feature class to sample | |
Returns: | |
feature layer sample of input feature class | |
""" | |
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