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