Hi all, Im working with ArcGIS Pro 3.0.0. I have polygon layer with 5400 attributes, and I need to split them randomly in ration of 80% to 20%, so than I will have two polygon layers with 4320 attributes and 1080.
What can I use for the random split?
Thank you all!
Have a nice day.
Solved! Go to Solution.
This Python script will create 2 layers (named "20%" and "80%") in your ArcGIS Pro map. These show the input features, but with a definition query. If you want to save those subsets, right-click on the layers and export data.
Copy/paste the script into the Python window, edit the in_features variable, run it.
in_features = "EZG" # path to the featureclass or name of the layer
import random
# get all objectids
oids = [row[0] for row in arcpy.da.SearchCursor(in_features, ["OBJECTID"])]
# get a random sample
oids_80 = random.sample(oids, int(0.8 * len(oids)))
# create the layers
arcpy.management.MakeFeatureLayer(in_features, "80%", f"OBJECTID IN {tuple(oids_80)}")
arcpy.management.MakeFeatureLayer(in_features, "20%", f"OBJECTID NOT IN {tuple(oids_80)}")
This Python script will create 2 layers (named "20%" and "80%") in your ArcGIS Pro map. These show the input features, but with a definition query. If you want to save those subsets, right-click on the layers and export data.
Copy/paste the script into the Python window, edit the in_features variable, run it.
in_features = "EZG" # path to the featureclass or name of the layer
import random
# get all objectids
oids = [row[0] for row in arcpy.da.SearchCursor(in_features, ["OBJECTID"])]
# get a random sample
oids_80 = random.sample(oids, int(0.8 * len(oids)))
# create the layers
arcpy.management.MakeFeatureLayer(in_features, "80%", f"OBJECTID IN {tuple(oids_80)}")
arcpy.management.MakeFeatureLayer(in_features, "20%", f"OBJECTID NOT IN {tuple(oids_80)}")
Thank you! It works.
Have a nice day!
Júlia