2

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 29, 2016 at 10:51

1 Answer 1

4

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.

answered Sep 29, 2016 at 11:04
6
  • 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? Commented 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. Commented Sep 29, 2016 at 11:41
  • By the way, which version of ArcGIS do you use? The Calculate Field expression I first suggested should work, but there is a bug in 10.2.1 - which doesn't seem to be solved yet anyway. Commented Sep 29, 2016 at 11:52
  • 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) >>> Commented 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. Commented Sep 29, 2016 at 12:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.