Randomly Sample Raster Cells of a Certain Value that are A Specified Distance Apart With a Script

852
2
04-28-2022 11:23 AM
DapperWrapperMapper
New Contributor II

My goal is to write a script that randomly samples a desired number of inputted N raster cells of a certain raster value/classification, and that these sampled cells be at least a specified inputted distance apart. After assembling this sample, I would like to export the latitude and longitude of these sampled cells to a spreadsheet.

 

I am using ArcMap 10.8 and I write in python with IDLE.

I have a .tif raster file of a large area. The size of an entire country. It has raster cells that are small, 30 x 30 m with roughly 180,000,000 classified as 0 and 150,000,000 classified as 1. I would like to write a script where I input a number of points that I want to be randomly sampled out of the category I desire and that these points are at least a distance that I determine apart from each other. Let’s just say, I want 1000 points of the raster cells that are classified as 1 and that they are at least 5 kms away from each other. I’d want to acquire the latitude and longitude of these cells—I imagine the center of the raster cell will do, but such precision is not necessary as 30 x 30 m is already very detailed. Then I’d like to export the latitude and longitude of these points to a .csv file or an excel sheet. How is the best way to go about doing this? I’m imagining efficiency might be a bit of a problem.

 

Right now, my thought process is this:

  1. make a new .tif of just the cells with the desired value/category (1 in this case).
  2. Randomly sample a cell, (not sure which tool to use).
  3. Put coordinates of sampled cell into some table (not sure which tool to use)
  4. Draw a buffer (5kms in this case) around sampled cell.
  5. Make new .tif with the buffer area around previously sampled point excluded from eligible points to be sampled.
  6. Repeat steps 2-6, 999 more times.
  7. Export table to .csv

 

 

Does anyone have any suggestions on a better way? Also, does anyone know what tools I would be looking for to accomplish this task?

 

Thanks a lot in advance for any wisdom that you may give.

0 Kudos
2 Replies
by Anonymous User
Not applicable

1. Raster to Polygon on your classified raster.

2. Create Random Points. Constraining Feature Class parameter will be the classified polygons you desire from step 1. You can also set the number of points and minimum distance.

3. Export coordinate geometry.

You mentioned accuracy in your post - this method doesn't guarantee you get the exact cell coordinates. But if that level of accuracy is acceptable might be worth a shot.

0 Kudos
DapperWrapperMapper
New Contributor II

and_viceversa,

 

thanks for this reply. I'm attempting to write this script now and see if this works. I'll come back and let you know. Thank you for this idea. I think I get it and it shows promise

0 Kudos