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 output
    • csv: 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 -l flag outputs the category labels of the matched raster objects at the beginning of the line, if they exist.
  • -o β€” the -o flag 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