I am working with a maximum water elevation raster in which, similarly to using r.grow.distance, I am trying to extract the distance from the each null cell to the nearest water elevation cell. However I need both the x and y distances, which are not provided by r.grow.distance. I looked into the source code for this function and found that the x and y distances are calculated within the code but r.grow.distance can only provide results in euclidean, squared, maximum, manhattan, or geodesic formats. Is there an easy way to extract these x and y distance values? If so, I am working on a real-time storm surge model so it would be ideal to be able to calculate these values in as little time as possible. I also looked into r.distance but this does not seem like an option that would work for me.Sample water elevation raster

  • 1
    Please edit your original question with additional info from comment and remove comment. – TomazicM May 23 '19 at 17:21
  • So you have a region that is partly covered by water, and all the rest are pixels with NULL? And you want the distance from all NULL pixels to the water, but split into X-Y components? Perhaps an image would make the question clearer. – Micha May 23 '19 at 19:14
  • Micha, that is correct. I am essentially trying to pull distance values from r.grow.distance as x and y components. I have added an image of the sample water elevation raster I have been working with. This raster represents the maximum water levels achieved throughout the duration of Hurricane Florence within a small area of the eastern coast of the United States. – Carter Rucker May 28 '19 at 15:18
  • @Micha Sorry, I just realized I did not properly use the @ in my previous comment (I'm new to this). If you are interested in seeing how I was able to resolve this issue, I have posted an answer to this thread. – Carter Rucker Jun 18 '19 at 15:50

I was able to use r.mapcalc to create a raster for all of the x and y values of the original maximum elevation raster. For example:


Then I used r.grow.distance to extrapolate the x and y values, covering all null cells. Finally, I used r.mapcalc and simply found the difference between the x() and y() moving-window values and the values extrapolated using r.grow.distance.

This gave me the x and y components of the euclidean distances between each null cell and its closest non-null cell.

  • Nice! Thanks for posting the solution. – Micha Jun 19 '19 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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