0

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!

4
  • Is the Euclidean distance tool not creating the output you desire? If so what's wrong?
    – Hornbydd
    Commented 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
    Commented Aug 4, 2021 at 17:50
  • 2
    Your solution is slow. Consider running distance on a new raster Con(original,original). It's raster calculator expression to replace points creation.
    – FelixIP
    Commented Aug 4, 2021 at 19:43
  • 2
    You 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. Commented Aug 4, 2021 at 21:28

1 Answer 1

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!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.