I have a raster with cells that have a value of either 0 or 1. What I would like to do is create a new raster that shows the distance of each cell to the nearest cell with a value of 1.
For all cells with value 1, this distance would then obviously return '0'. For all cells with value 0, it would give me the distance to the nearest cell with value '1'.
I have been playing around with the Euclidean distance function in Arcmap but I feel like an extra step is required? The output currently just gives '0' distance for all cells that have a value in the input raster (0 or 1). enter image description here
I am comfortable doing this in both Arcmap or R.
EDIT- SOLUTION FOUND: Change the raster to a points shapefile, it will create a column with values 0/1. Then delete the 0 values. Then create a euclidean distance raster to what remains of this shapefile, and clip as desired. this works although it seems a little convoluted!
-
Is the Euclidean distance tool not creating the output you desire? If so what's wrong?Hornbydd– Hornbydd2021年08月04日 16:30:12 +00:00Commented Aug 4, 2021 at 16:30
-
I found a way: Change the raster to a points shapefile, it will create a column with values 0/1. Then delete the 0 values. Then create a euclidean distance raster to what remains of this shapefile, and clip as desired. this works although it seems a little convoluted!Beardedant– Beardedant2021年08月04日 17:50:19 +00:00Commented Aug 4, 2021 at 17:50
-
2Your solution is slow. Consider running distance on a new raster Con(original,original). It's raster calculator expression to replace points creation.FelixIP– FelixIP2021年08月04日 19:43:00 +00:00Commented Aug 4, 2021 at 19:43
-
2You do not need to turn the raster into a shapefile. Just turn the zero values to nodata and then run the raster distance function. It will be massively faster.Jeffrey Evans– Jeffrey Evans2021年08月04日 21:28:14 +00:00Commented Aug 4, 2021 at 21:28
1 Answer 1
Fastest way: turn the zero values to nodata and then run the raster distance function. It will be massively faster (Thanks to Jeffrey Evans)
or..
Change the raster to a points shapefile, it will create a column with values 0/1. Then delete the 0 values. Then create a euclidean distance raster to what remains of this shapefile, and clip as desired. this works although it seems a little convoluted!