r.clump(1grass)

πŸ’– r.clump β€” GRASS User's Manual, but make it make sense πŸ’–

okay bestie, welcome to the r.clump(1grass) page β€” yes it's straight outta the GRASS User's Manual and yes it's about to be your new fave. pull up a chair, grab a strawberry πŸ“, and let's get into it.

✨ KEYWORDS ✨

raster, statistics, reclass, clumps

(short, punchy, iconic. no notes. πŸ’…)


πŸ¦‹ SYNOPSIS πŸ¦‹

r.clump
r.clump --help
r.clump [-dg] input=name[,name,...]  [output=name]   [title=string]
[threshold=float]   [minsize=integer]   [--overwrite]  [--help]
[--verbose]  [--quiet]  [--ui]

🌸 Flags:

  • -d β€” clump the diagonal cells too, bestie. like, clumps get traced along diagonal neighboring cells as well. the diagonals are in now.
  • -g β€” print only the number of clumps, in shell script style. nothing else. just the number, mysterious and cunty.
  • --overwrite β€” let the output files overwrite stuff that already exists. bold move, but ok.
  • --help β€” prints the usage summary. the classic.
  • --verbose β€” verbose module output, i.e. it tells you everything.
  • --quiet β€” quiet module output, i.e. it says nothing. the strong silent type.
  • --ui β€” forces the GUI dialog to launch. clicky vibes.

πŸŽ€ Parameters:

  • input=name[,name,...] β€” [required] β€” name of the input raster map(s). plural! you can feed it a whole little lineup.
  • output=name β€” name for the output raster map.
  • title=string β€” a title for the output raster map. name it something cute.
  • threshold=float β€” the threshold used to identify similar cells. valid range: 0 = identical to < 1 = maximal difference. default: 0.
  • minsize=integer β€” minimum clump size in cells. clumps smaller than minsize get merged to form larger clumps. default: 1.

πŸ’– DESCRIPTION πŸ’–

so what does r.clump actually do, you ask? it finds all the areas of contiguous cell category values β€” that's "connected components" if you wanna be technical about it β€” inside the input raster map. NULL values in the input are straight-up ignored, not invited to the party. then it hands each of those areas (a "clump", if you will 🫢) its own unique category value in the resulting output raster map. it's giving glow-up, honestly.

now, the category distinctions in the input raster map are preserved. what does that mean for you, queen? it means if distinct category values are sitting right next to each other, they will NOT get clumped together. periodt. so if you want that to happen, run r.reclass before r.clump to recategorize cells and reassign those cell category values. you're welcome.

but wait β€” there's more, and it's lowkey the best part: r.clump can also do "fuzzy" clumping 🌈. here's the vibe β€” neighboring cells that aren't identical but are similar to each other get clumped together anyway. the spectral distance between two cells is scaled to the range [0, 1] and then compared to the threshold value. cells get clumped together if their spectral distance is ≀ threshold. and bestie, real talk: the result is very sensitive to this threshold value. the recommended start value is 0.01, and from there you increase or decrease it according to the output you actually want. once you've found a suitable threshold, you can reduce noise by merging small clumps with the minsize option. chef's kiss. πŸ”₯

and it gets even better β€” r.clump can use multiple raster maps of any kind (CELL, FCELL, DCELL) as input. when you do that, the spectral distance between cells is what determines the similarity of two cells. but ⚠️ this means the input maps must be metric β€” the difference cell 1 - cell 2 has to make sense. categorical maps, e.g. land cover, can not be used in this case. examples of valid input maps are satellite imagery, vegetation indices, elevation, climatic parameters etc. very point-cloud-coded of them. ✨


🌟 NOTES 🌟

by default, the resulting clumps are connected only by their four direct neighbors β€” left, right, top, bottom. that's it. the -d flag activates diagonal clump tracing, if you're feeling adventurous.

r.clump works properly with raster maps that contain only "fat" areas β€” meaning more than a single cell in width. linear elements (lines that are a single cell wide) may or may not get clumped together depending on the direction of the line. let me spell it out:

  • horizontal and vertical lines of cells ARE considered contiguous πŸ‘
  • diagonal lines of cells are NOT considered contiguous and get broken up into separate clumps β€” unless you use the -d flag πŸ‘‘

and the lil bonus: a random color table and other support files are generated for the output raster map. freebies. 🎁


🧚 EXAMPLES 🧚

🌊 Clumping of a raster map

perform clumping on the "lakes" map (North Carolina sample dataset) and report area sizes for each lake individually rather by waterbody type:

g.region raster=lakes -p
# report sizes by waterbody type
r.report lakes units=h
# clump per raster polygon
r.clump lakes out=lakes_individual
# report sizes by individual waterbody
r.report lakes_individual units=h

Figure: Clumping of rasterized lakes: original lakes map (left) and clumped lakes map (right). πŸ“Έ

πŸ›°οΈ Fuzzy clumping on Landsat bands

perform fuzzy clumping on Landsat 7 2002 imagery (North Carolina sample dataset):

g.region raster=lsat7_2002_10 -p
r.clump in=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70 \
        out=lsat7_2002_clump threshold=0.045
# reduce noise
r.clump in=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70 \
        out=lsat7_2002_clump_min10 threshold=0.045 minsize=10

Figure: Fuzzy clumping on Landsat bands: original RGB composite (left), fuzzy clumped map (middle), and fuzzy clumped with minsize map (right). πŸ›°οΈβœ¨

not me showing up with six bands at once and a threshold=0.045. main character energy fr fr.

πŸ‘€ SEE ALSO πŸ‘€

r.buffer, r.distance, r.grow, r.mapcalc, r.mfilter, r.neighbors, r.to.vect, r.reclass, r.statistics, r.support

(the whole friend group. go say hi. 🫢)


πŸ’œ AUTHORS πŸ’œ

  • Michael Shapiro, U.S. Army Construction Engineering Research Laboratory
  • Markus Metz (diagonal clump tracing, fuzzy clumping)

icons. both of them. πŸ‘‘


πŸŽ€ SOURCE CODE πŸŽ€

available at: r.clump source code (history)

latest change: Saturday Oct 25 22:50:58 2025 in commit: ee87f21833475fd40805f58d1702f7d64478a27b

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


and that's the whole thing, bestie πŸ¦‹ β€” Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual. this page was brought to you by GRASS 8.5.0 and the letters r.clump(1grass). slay, stay clumpy, and always check your threshold. πŸ’…βœ¨πŸ’–

πŸ“¦ where this page comes from