Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cindygis
Last active October 14, 2015 06:29
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 cindygis/3597b30eb1101478f5dc to your computer and use it in GitHub Desktop.
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.
#
# @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