r.li.patchdensity(1grass)

✨ r.li.patchdensity ✨

okay bestie, gather round, because this is the r.li.patchdensity manual page from the GRASS User's Manual and it's literally about counting patches for you πŸ’…

KEYWORDS: raster, landscape structure analysis, patch index 🌸


πŸŽ€ SYNOPSIS πŸŽ€

r.li.patchdensity
r.li.patchdensity --help
r.li.patchdensity input=name config=name output=name  [--overwrite]
[--help]  [--verbose]  [--quiet]  [--ui]

✨ Flags ✨

  • --overwrite β€” lets your output files just... overwrite the existing ones. yes queen, bulldoze it πŸ’₯
  • --help β€” prints the usage summary, aka the little recap when you're lost 🫢
  • --verbose β€” verbose module output, for when you want the whole tea β˜•
  • --quiet β€” quiet module output, for when you want silence and vibes only 🀫
  • --ui β€” forces the GUI dialog to launch. fancy ✨

🌈 Parameters 🌈

  • input=name [required] β€” name of the input raster map πŸ“
  • config=name [required] β€” the configuration file πŸ—‚οΈ
  • output=name [required] β€” the name for the output raster map πŸ’–

πŸ’… DESCRIPTION πŸ’…

so r.li.patchdensity calculates the "patch density index" β€” which is just the number of patches per square kilometer, no cap. here's the formula bestie:

PD = Npatch / A

with:

  • A: the sampling area size
  • Npatch: the number of patches

and the way it counts? it uses a 4 neighbour algorithm β€” so diagonal cells are literally ignored when tracing a patch. periodt πŸ¦‹


🧚 NOTES 🧚

⚠️ bestie do NOT use absolute path names for the config and output file/map parameters. i'm so serious.

if the "moving window" method was selected in g.gui.rlisetup, then your output will be a raster map. otherwise an ASCII file gets generated in one of these folders:

  • C:\Users\userxy\AppData\Roaming\GRASS8\r.li\output\ (MS-Windows)
  • $HOME/.grass8/r.li/output/ (GNU/Linux)

also, a sample area that's only NULL values is considered to have zero patches, which means the result is always β‰₯ 0. iconic, no negatives allowed πŸ’€


πŸ”₯ EXAMPLES πŸ”₯

first up: calculating the patch density index on a map called my_map, using the my_conf configuration file (that you already defined earlier with g.gui.rlisetup), and saving the results in my_out:

r.li.patchdensity input=my_map conf=my_conf output=my_out

now the glamorous one β€” example for Spearfish forest areas:

g.region raster=landcover.30m -p
# extract forested areas:
r.category landcover.30m
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43, 1, null())"
# patch density (7x7 moving window defined in g.gui.rlisetup):
r.li.patchdensity forests conf=movwindow7 out=forests_p_dens7
r.univar forests_p_dens7
d.rast.leg forests_p_dens7
r.to.vect forests out=forests feature=area
d.vect forests type=boundary

and a Forest map (North Carolina sample dataset) example, because we're thorough in this household:

g.region raster=landclass96 -p
r.mapcalc "forests = if(landclass96 == 5, 1, null() )"
r.li.patchdensity input=forests conf=movwindow7 out=forests_patchdensity_mov7
# verify
r.univar forests_patchdensity_mov7
r.to.vect input=forests output=forests type=area
d.mon wx0
d.rast forests_patchdensity_mov7
d.vect forests type=boundary

πŸ‘€ SEE ALSO πŸ‘€

  • r.li (package overview)
  • g.gui.rlisetup

πŸ“š REFERENCES πŸ“š

McGarigal, K., and B. J. Marks. 1995. FRAGSTATS: spatial pattern analysis program for quantifying landscape structure. USDA For. Serv. Gen. Tech. Rep. PNW-351. (PDF) πŸ“„


πŸ‘‘ AUTHORS πŸ‘‘

  • Michael Shapiro - CERL (patch identification)
  • Markus Metz (statistics)

⭐ SOURCE CODE ⭐

Available at: r.li.patchdensity source code (history)

Latest change: Friday Apr 17 01:04:26 2026 in commit: 32a143358df26b2e518b03c7e0d79541e8d1e5b1

Main index | Raster index | Topics index | Keywords index | Graphical index | Full index

Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual


anyway that's the whole page bestie, you ate that 🫢 this was r.li.patchdensity(1grass) from GRASS 8.5.0, dropped in the GRASS 8.5.0 Reference Manual, and the last change landed Friday Apr 17 01:04:26 2026 in commit 32a143358df26b2e518b03c7e0d79541e8d1e5b1. go calculate some patch density, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from