# How do I get the distances to every cell in GRASS?

I have an elevation raster map, a point, a raster map defining the viewshed from that point, and now I want to produce another raster map with the results of a function of the distance between the point and every point (cell) in the elevation map that has a defined value (not equal to 180) in the viewshed raster map. The function the distance that I want to compute between the point and the cells in the elevation map is the inverse square law.

How do I do that using GRASS?

• You need to state which GIS and which version you are using. Sep 13, 2015 at 15:16
• GRASS 6.4.1 (2011) running on Ubuntu 12.04 LTS Sep 13, 2015 at 15:31

You could use the `r.buffer` function. But it uses classes for the distance.

``````r.buffer input=roads output=roads.buf distances=100,200,300,400,500
``````

The result would be:

``````  roads                    roads.buf
000000000000000000000000 222233333333333333444444
111000000000000000000000 111222222222223333333333
000111111111100000000000 222111111111122223333333
000000001000011100000000 332222221222211122222222
000000001000000011111111 333333321233222211111111
000000001000000000000000 433333321233333222222222
000000001000000000000000 444443321233333333333333
000000001000000000000000 444443321233443333333333
000000001000000000000000 444443321233444444444444
``````
• Better use r.grow.distance (grass.osgeo.org/grass70/manuals/r.grow.distance.html) which generates a raster map containing distances to nearest raster features. Sep 18, 2015 at 10:20
• Wow. Ideally would want the actual 3-dimensional distance taking into account all of the elevations in the elevation raster map corresponding only to those points that are non-null in the viewshed raster. The point also has its own height which may be independent of the height of the topography in the elevation raster. Oct 8, 2015 at 17:22
• 3D distance wouldn't be much more difficult. r.grow.distance can give you r^2 = x^2+y^2. You could use r.mapcalc to get z^2, e.g., r.mapcalc z2=(z_elevation-z_point)^2. And use r.mapcalc again, e.g., r.mapcalc 3d_dist=sqrt( r2 + z2 ). Feb 24, 2016 at 13:43