r.distance(1)
β¨ r.distance β¨
okay bestie, gather round, because this is the GRASS GIS User's Manual page for r.distance, and it is genuinely one of the most useful little tools in the whole raster toolbox, no cap π
π NAME π
r.distance β finds the closest points between objects living in two raster maps. like, it's giving matchmaker but for grid cells π
π KEYWORDS π
raster, distance
π¦ SYNOPSIS π¦
r.distance
r.distance --help
r.distance [-lon] map=name1,name2[,name1,name2,...]
[separator=character] [sort=string] [--help] [--verbose] [--quiet]
[--ui]
π© Flags
-lβ bestie, include those category labels in the output, they matter π-oβ if the rasters are overlapping, just report zero distance. overlapping? zero. periodt.-nβ report null objects as*. yes, the literal asterisk. iconic.--helpβ prints the usage summary, for when you're lost (we've all been there π)--verboseβ verbose module output, aka it tells you EVERYTHING--quietβ quiet module output, aka it tells you nothing, main character silence β¨--uiβ force launches the GUI dialog. fancy. slay.
πΈ Parameters
map=name1,name2[,name1,name2,...]β required, bestie, you literally cannot skip this one. name of the two input raster maps you want inter-class distances for.separator=characterβ the field separator. special characters you can use: pipe, comma, space, tab, newline. Default::sort=stringβ sorts the output by distance. Default: sorted by categories. Options:asc,descasc: sort by distance in ascending order (smallest first, lil baby distances π₯Ί)desc: sort by distance in descending order (biggest first, dramatic distances π)
π DESCRIPTION π
so r.distance locates the closest points between "objects" in two raster maps. and what even is an "object", you ask? an "object" is defined as all the grid cells that have the same category number, and "closest" means having the shortest "straight-line" distance. the cell centers are what we're measuring from β so two adjacent grid cells have the distance between their cell centers. not the edges. the centers. important. π«Ά
the output is an ascii list, one line per pair of objects, looking exactly like this:
cat1:cat2:distance:east1:north1:east2:north2
and here's the breakdown, no gatekeeping:
cat1β category number from map1cat2β category number from map2distanceβ the distance in meters betweencat1andcat2east1,north1β the coordinates of the grid cellcat1which is closest tocat2east2,north2β the coordinates of the grid cellcat2which is closest tocat1
β¨ Flags β¨
-lβ the-lflag outputs the category labels of the matched raster objects at the beginning of the line, if they exist. if they don't exist... they just don't show up. vibe check failed, moving on.-oβ the-oflag reports zero distance if the input rasters are overlapping.
π NOTES π
the output format lends itself to filtering, which is lowkey the best part. for example, to "see" lines connecting each of the category pairs in two maps, you filter the output using awk and then pipe it into d.graph:
r.distance map=map1,map2 | \
awk -F: β{print "move",$4,$5,"\ndraw",$6,$7}β | d.graph -m
and to create a vector map of all the map1 coordinates, you filter the output into awk and then into v.in.ascii:
r.distance map=map1,map2 | \
awk -F: β{print $4,$5}β | v.in.ascii format=point output=name separator=space
like?? the way it just slots into your pipeline?? obsessed. π₯
π SEE ALSO π
r.buffer, r.cost, r.drain, r.grow, r.grow.distance, v.distance
π AUTHOR π
Michael Shapiro, U.S. Army Construction Engineering Research Laboratory
π§ SOURCE CODE π§
available at: r.distance source code (history)
accessed: Saturday Jan 17 05:40:45 2026
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole page, bestie, you ate it up π this was the GRASS GIS 8.4.2 Reference Manual, brought to you by the GRASS Development Team, Β© 2003-2025 β and the access date on the source was Saturday Jan 17 05:40:45 2026, so like, mark your calendar or whatever. go compute some distances, ily π¦πΈπ
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms