Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.


I would like to create a raster where each cell contains the vertical distance to the nearest water (a decent approximation would be acceptable). The problem is that I'm not sure how to go about it.

Current approach:

I've looked through the documentation for my GIS (I'm using Grass 6.4 if that matters). And I can't find any direct way to perform this calculation. I've also searched the web without luck.

So I dreamed up the following:

  • convert my water vector to a water raster (1=water, null=everything else)
  • replace the 1s in the water raster with the altitude above sea level
  • perform "neighborhood" (moving window) analysis. Calculate the average altitude of water for a 100 meter radius for every cell in my region (ignoring nulls)
  • repeat the above with 100m, 200m, 300m, ..., 2000m. One raster for each distance.
  • using r.grow.distance calculate the distance between each cell and it's nearest water
  • then, using map algebra, I look at the distance to nearest water for each cell and its own altitude and subtract the average altitude of water for the appropriately distanced raster.

The problems with my method:

  • It is very computationally demanding. I am working at a 10m resolution and I need to perform this modelling on around 60 million cells. I've been creating rasters on a fast desktop for days and days and I'm not even close to finished.

  • At small radii, the calculation seems reasonable. If the distance to nearest water is 75 meters and I use a 100 m average altitude to water, the approximation is pretty good. But if the distance to nearest water is 1875 meters and I use the 1900 meter raster I will be averaging in the altitude to water of many cells far removed from the nearest water to my cell. The results are dissatisfying. I considered using some kind of smoothing process for the final raster but I wonder if there is a completely different approach that I am not seeing.

I've been reading about predictive modeling projects where vertical distance to nearest water is a one of the inputs to the model so I know it can be done but I'm just not sure how.

I'd appreciate any help I can get with this problem. Thanks.

share|improve this question
In arcgis you could use the euclidean allocation function + some map algebra. I know you don't have that software but maybe there's a source for the calculation? –  blindJesse Apr 18 '11 at 5:29
add comment

1 Answer

up vote 7 down vote accepted

Perform a hydrologic analysis on your data. Taking your first step of water bodies as a raster, you can then use that as a sinks raster. I'll specify the rest of this analysis in terms of GRASS as you mentioned that's the GIS system you're using:

Set up r.watershed (documentation) with the elevation data layer you'd like to analyze and the sinks raster you generated in the first step:

r.watershed elev=input_dem depression=input_sinks basin=output_basins \ 
  stream=output_streams threshold=1000

Where threshold is something appropriate for the scale of your data-- this should give you a map of each watershed: if you subtract that elevation from all the cells in that basin, you should get the vertical distance to the nearest water. You may need to iterate over smaller regions than your full raster to get good performance. You might find these tutorials (1, 2) also helpful in understanding how to use the command.

Mike helpfully mentioned an addon called r.watershed.distance which can be used to calculate this all in one go:

r.stream.distance -o dir=dirs stream=streams dem=elev \ 
  distance=distance_outlets  elevation=elevation_outlets

Which will result in an output close to what you're interested in: http://grass.osgeo.org/grass-wiki/images/Distance_outlets.png

This example was taken from the R.stream.* page, you can download the extension itself from the addon page.

share|improve this answer
There are a few gems in GRASS for hydrological sciences, such as r.stream.distance (based on r.watershed) that calculates downslope distance and downslope elevation difference to stream or outlet cells –  Mike T Apr 18 '11 at 9:06
Thank-you. I've been pulling my hair out on this one. r.stream.distance looks perfect. I'll install it tomorrow. –  blaine Apr 19 '11 at 4:18
I have thought of one issue with this technique: if you have a waterbody in an adjacent but close basin, it won't give you the distance to it going 'uphill' over the ridge first. It'd still be possible, but a bit more tricky to implement. –  scw Apr 19 '11 at 17:52
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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