How can I assign a specific number of random points based on acreage?

5024
19
02-01-2016 09:33 AM
JamesLabate
New Contributor II

Hello,

Can someone tell me how to generate a specific number of random points based on the acreage of a polygon falling within a specified range?

Is there a way to make the Create Random Points tool generate a specific number of  points based on the comparison of an area field to an area range?

is there another tool or combination of whic I can use?

This is what I'm talking about:

So, I have 158 polygons in my timber stand layer.   I am trying to assign

random points to each individual polygon based on their acreage.  So the

breakdown is as follows:

Size of polygon in acres----number of random points required----number of

polygons of this size on the layer.

0-10acres---3points---4polygons

10-20acres---4---37

20-30acres---5---39

30-40acres---6---20

40-50acres---7---11

50-60acres---8---17

60-70acres---9---13

70-80acres---10---6

80-90acres---11---2

90-100acres---12---3

100-110acres---13---3

133acres---16---1

155acres---18---1

I would like to have the points evenly distributed if possible, if not, they

need to be a minimum of 100meters apart.

Thanks in Advance,

Jim Labate

Tags (1)
0 Kudos
19 Replies
JamesLabate
New Contributor II

Thanks for hanging in there with this Xander. I am far from expert with arcpy.

What confuses me about

  1. from random import uniform 
  2. lst_areas = [] 
  3. for i in range(0, 100😞 
  4.     lst_areas.append(uniform(4.5, 110)) 
  5. lst_areas += [133, 155
  6. for area in sorted(lst_areas): 
  7. print area, int(area // 10) + 3

. . . is I don't see how the acreage field in my input file is evaluated. That's what the whole chin of logic is based on.

  • Look at the acreage value
  • determine acreage range it falls within
  • assign the acreage ranges number of random points  to the numPts variable
  • run the CreateRandomPoints tool.

Sorry for being a arcpy newbie. Thanks for the help.

Jim

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi James Labate , the code that I included does not evaluate your data. It only generates a list with 100 values raging from 4.5 to 110 and adding the values 133 and 155 to this list. I don't have access to your data, it merely served to generate a list that contains values similar to the values you have. With this list I can explain that the logic in the script you are using is not correct and will not process all the features you have in your featureclass.

So the logic applied to your specific case would yield something like this:

import arcpy
from arcpy import env
#Specify workspace
env.workspace = r"C:\GIS\BrettWalker\PointsByAcreage.gdb"
env.overwriteOutput = True

#Specify Feature Class
fc = r"C:\GIS\BrettWalker\PointsByAcreage.gdb\TimberInventoryStands"

#Iterate through feature class by Ascending order for the field Acres
with arcpy.da.SearchCursor(fc, ["OBJECTID", "Acres"], sql_clause=("ASC", "ORDER BY Acres")) as cursor:
    for row in cursor:
        arcpy.MakeFeatureLayer_management(fc, "fLayer", "OBJECTID = {0}".format(row[0]))
        numPts = int(row[1] // 10) + 3
        arcpy.CreateRandomPoints_management(env.workspace, "pts{0}".format(row[0]), "fLayer", "", numPts, "100 Meter")

del cursor

list = []
for fc in arcpy.ListFeatureClasses("Pts*"):
    list.append(fc)

#Merge all point feature classes
arcpy.Merge_management(list, "RandomPoints")

#Delete individual point feature classes
for fc in arcpy.ListFeatureClasses("Pts*"):
    arcpy.Delete_management(fc)

See how it simplifies the code?

XanderBakker
Esri Esteemed Contributor

With respect to point 2; it is generating a random location. If this falls in the middle of the polygon, there may not ne enough room to generate the other point.

The method used is explained here: How Create Random Points works—Help | ArcGIS for Desktop

DanPatterson_Retired
MVP Emeritus

I am with you on this one Xander... hs anyone looked at the features that are problematic??

0 Kudos
JamesLabate
New Contributor II

Hi Dan,

My input feature class of  forest stands has an acreage field that is being read; it's value measured against a range which in turn assigns the numPts variable a value. numPts is the parameter plugged into CreateRandomPoints. SearchCursor does seem to be cycling through every Acre field value and then executing the MakeFeatureLayer tool, but that tool - after opening up for every polygon in the fc - does not seem to see any values in any of the fields?

Executing: MakeFeatureLayer C:\GIS\BrettWalker\PointsByAcreage.gdb\TimberInventoryStands fLayer "OBJECTID = 84" # "OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;AREA_SIZE AREA_SIZE VISIBLE NONE;INV_PA_AC_ INV_PA_AC_ VISIBLE NONE;STD_AC STD_AC VISIBLE NONE;FEAT_ID_ FEAT_ID_ VISIBLE NONE;standID standID VISIBLE NONE;treatment_ treatment_ VISIBLE NONE;remarks remarks VISIBLE NONE;siteindex siteindex VISIBLE NONE;sispecies sispecies VISIBLE NONE;total_basa total_basa VISIBLE NONE;AGS_ba AGS_ba VISIBLE NONE;medial_dia medial_dia VISIBLE NONE;eff_age eff_age VISIBLE NONE;gross_bdft gross_bdft VISIBLE NONE;net_bdft_v net_bdft_v VISIBLE NONE;value value VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE;Shape_Area Shape_Area VISIBLE NONE;Acres Acres VISIBLE NONE"

So CreateRandomPoints never gets executed.

To be clear, there is no compromising on the input fc - it is a layer of polygons at different acreages. The number of random points to be generated depends on what 10 acre range a particular polygon's acreage falls into.

I don't follow how Xander's simplified code takes into account the acreages of the input fc's polygons

Thanks for the help,

Jim

0 Kudos
JamesLabate
New Contributor II

Kind of like the tail wagging the dog then isn't it - if the number of points parameter doesn't drive the placement of the first point. Still I'm not getting any points placed after the first polygon

0 Kudos
JamesLabate
New Contributor II

Jake,

Hope you saw my first response and also what I wrote to Xander. I'll also add this bit of the result output.

MakeFeatureLayer does execute for every polygon in the fc but nothing seems to be "visible" to it - see below one example - 157 others similar

Executing: MakeFeatureLayer C:\GIS\BrettWalker\PointsByAcreage.gdb\TimberInventoryStands fLayer "OBJECTID = 84" # "OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;AREA_SIZE AREA_SIZE VISIBLE NONE;INV_PA_AC_ INV_PA_AC_ VISIBLE NONE;STD_AC STD_AC VISIBLE NONE;FEAT_ID_ FEAT_ID_ VISIBLE NONE;standID standID VISIBLE NONE;treatment_ treatment_ VISIBLE NONE;remarks remarks VISIBLE NONE;siteindex siteindex VISIBLE NONE;sispecies sispecies VISIBLE NONE;total_basa total_basa VISIBLE NONE;AGS_ba AGS_ba VISIBLE NONE;medial_dia medial_dia VISIBLE NONE;eff_age eff_age VISIBLE NONE;gross_bdft gross_bdft VISIBLE NONE;net_bdft_v net_bdft_v VISIBLE NONE;value value VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE;Shape_Area Shape_Area VISIBLE NONE;Acres Acres VISIBLE NONE"

Start Time: Fri Feb 26 16:19:16 2016

Succeeded at Fri Feb 26 16:19:16 2016 (Elapsed Time: 0.00 seconds)

Is the tool not temporarily creating the polygon?

Thanks,

Jim

0 Kudos
DarrenWiens2
MVP Honored Contributor

You just need to get the number of points per polygon into a new field holding the number of points you want. There are many ways to do it, but this Python codeblock should work (the expression is: myFunc(!area!)):

def myFunc(area):
  if area == 133:
    return 16
  if area == 155:
    return 18
  return math.floor( area/10+3 )

Then, run CreateRandomPoints with your points field in the number_of_points_or_field and 100 for minimum_allowed_distance.

I don't think there is a simple answer to meet your need for evenly distributing points, if possible.

RobertBorchert
Frequent Contributor III

Little to fancy.

Create an attribute telling you how many points a polygon should have.

Populate the attribute with the number of points.

Run the Create Random points function.

name your output.

Constraining feature should be your polygon layer

Choose Number of points and field.  use the drop down to find the field.

Hit ok.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Not sure how this differs from the previous suggestions, except you're glazing over the non-trivial point of populating the attribute based on the value of another attribute. Are you suggesting to do 13 selection/calculate field operations?

0 Kudos