r.distance(1grass)
β¨ r.distance β¨
okay bestie, gather round β this is r.distance, and no cap it's lowkey one of the most useful tools in GRASS for "how far apart are these two things actually" energy. It lives in the GRASS User's Manual, and it's giving raster, distance vibes (those are the keywords, π
).
πΈ NAME πΈ
r.distance β locates the closest points between objects in two raster maps. That's it, that's the whole gig. π
π KEYWORDS π
raster, distance
π¦ SYNOPSIS π¦
r.distance
r.distance --help
r.distance [-lon] map=name1,name2[,name1,name2,...]
[separator=character] [sort=string] format=name [--help]
[--verbose] [--quiet] [--ui]
π Flags:
-lβ include category labels in the output. yes queen, labels.-oβ report zero distance if rasters are overlapping (they're touching, so likeβ¦ zero β)-nβ report null objects as*β star them out, iconic β--helpβ print usage summary (when u forgot how it works, we've all been there π)--verboseβ verbose module output (it will NOT stop talking)--quietβ quiet module output (shhh π€«)--uiβ force launching GUI dialog (for the visual girlies)
π Parameters:
map=name1,name2[,name1,name2,...]β required. Name of two input raster maps for computing inter-class distances. pair them UP bestie π«Άseparator=characterβ field separator. Special characters you can use: pipe, comma, space, tab, newline. pick ur ~vibe~ of separator.sort=stringβ sort output by distance. Default: sorted by categories. Options:asc,desc.asc: sort by distance in ascending order (small β big πΌ)desc: sort by distance in descending order (big β small π½)
format=nameβ required. output format. Options:plain,csv,json. Default:plain.plain: human readable text outputcsv: CSV (Comma Separated Values)json: JSON (JavaScript Object Notation)
π DESCRIPTION π
So r.distance locates the closest points between "objects" in two raster maps. And before you ask β an "object" here is defined as all the grid cells that have the same category number. and "closest" means having the shortest "straight-line" distance. periodt.
The cell centers are what get considered for the distance calculation, just so u know (two adjacent grid cells have the distance between their cell centers β that's the rule, iykyk).
The output is an ascii list, one line per pair of objects, in this form:
cat1:cat2:distance:east1:north1:east2:north2
Let's break down every single field, no skipping β¨:
- cat1 β category number from map1
- cat2 β category number from map2
- distance β the distance in meters between "cat1" and "cat2"
- east1,north1 β the coordinates of the grid cell "cat1" which is closest to "cat2"
- east2,north2 β the coordinates of the grid cell "cat2" which is closest to "cat1"
π§ Flags
-lβ the-lflag outputs the category labels of the matched raster objects at the beginning of the line, if they exist.-oβ the-oflag reports zero distance if the input rasters are overlapping.
π NOTES π
The output format lends itself to filtering β it's basically built for it, main character energy fr fr. For example, to "see" lines connecting each of the category pairs in two maps, filter the output using awk and then into d.graph:
r.distance map=map1,map2 | \
awk -F: β{print "move",$4,$5,"\ndraw",$6,$7}β | d.graph -m
To create a vector map of all the "map1" coordinates, 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
β 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 β shoutout legend, genuinely ate π«Ά
π₯ SOURCE CODE π₯
Available at: r.distance source code (history)
Latest change: Saturday Oct 11 04:38:40 2025 in commit: 3dd71f5fab83b72a2db2da959fe075c5b3b52200
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual
and that's the whole page bestie!! πβ¨ this was GRASS 8.5.0, r.distance(1grass), and yes ur girl read every single line so u didn't have to. slay, go measure some distances, no cap ππ¦
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· 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