Last active
October 14, 2015 06:29
-
-
Save cindygis/3597b30eb1101478f5dc to your computer and use it in GitHub Desktop.
Creates random points in each polygon feature. Bypasses the Advanced licence needed to run the Create Random Points tool in ArcMap.
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
# | |
# @date 06/08/2015 | |
# @author Cindy Williams | |
# | |
# Creates random points in each polygon feature | |
# without the need for an Advanced licence to run | |
# the Create Random Points tool. | |
# | |
# For use in the Python window in ArcCatalog. | |
# | |
import arcpy | |
import random | |
arcpy.env.workspace = r"C:\Some\Arb\Folder\work.gdb" | |
ftr_polys = "ftr_poly" | |
ftr_points = "ftr_points" | |
fields = ["SHAPE@", "Name"] | |
cursor_ins = arcpy.da.InsertCursor(ftr_points, fields) | |
with arcpy.da.SearchCursor(ftr_polys, fields) as cursor: | |
for row in cursor: | |
num_points = random.randint(1, 11) | |
poly_ext = [row[0].extent.XMin, | |
row[0].extent.XMax, | |
row[0].extent.YMin, | |
row[0].extent.YMax] | |
for n in xrange(num_points): | |
x = random.uniform(poly_ext[0], poly_ext[1]) | |
y = random.uniform(poly_ext[2], poly_ext[3]) | |
randpoint = [arcpy.PointGeometry(arcpy.Point(x, y)), row[1]] | |
cursor_ins.insertRow(randpoint) | |
del cursor_ins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment