I want my area filled radomly with a number of points with a number of random numerical values in the range i specify. Other than tediously creating each point and filling up random values, is there any better method?
1 Answer 1
If you have an Advanced license or Spatial Analyst or 3D Analyst, you can use the Create Random Points tool.
You can then add a field and populate it with random values within a specified range with this Python code snippet (change the fc
, field_name
and range values, then copy-paste the code in the Python window in ArcMap or ArcCatalog):
import arcpy, random
with arcpy.da.UpdateCursor(fc, "field_name") as cur:
for row in cur:
row[0] = random.randint(0, 100)
cur.updateRow(row)
This will generate integer values between 0 and 100. Python offers other random functions if you need another type of range.
-
Thanks. Generating random points was easy. But I am not being able to generate random values for those points. When I use the expression you gave, all the values of the field get populated by a single random value. There is no variation in its value. How do I solve this problem?Aakash Bikram Rana– Aakash Bikram Rana2016年09月29日 11:29:18 +00:00Commented Sep 29, 2016 at 11:29
-
Sorry, I've modified my answer to generate different random values for each row. Using Python is necessary for this.GISGe– GISGe2016年09月29日 11:41:56 +00:00Commented Sep 29, 2016 at 11:41
-
-
Its 10.3 but your code is not working. Could you see what mistake I did? I know nothing of python u know and I am new in GIS too. >>> import arcpy, random ... with arcpy.da.UpdateCursor("random_points","rainfall_in_mm") as cur: ... for row in cur: ... row[0]=random.randint(1000, 1400) ... cur.updateRow(row) ... Parsing error IndentationError: unexpected indent (line 1) >>>Aakash Bikram Rana– Aakash Bikram Rana2016年09月29日 12:04:26 +00:00Commented Sep 29, 2016 at 12:04
-
Make sure you respect the structure, indentation is important with Python: 0 tabs at line 1 and 2 - 1 tab at line 3 - 2 tabs at lines 4 & 5.GISGe– GISGe2016年09月29日 12:07:51 +00:00Commented Sep 29, 2016 at 12:07