Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

clump

Detect clumps


Description

Detect clumps (patches) of connected cells. Each clump gets a unique ID. NA and zero are used as background values (i.e. these values are used to separate clumps). You can use queen's or rook's case, using the directions argument. For larger files that are processed in chunks, the highest clump number is not necessarily equal to the number of clumps (unless you use argument gaps=FALSE).

Usage

## S4 method for signature 'RasterLayer'
clump(x, filename="", directions=8, gaps=TRUE, ...)

Arguments

x

RasterLayer

filename

Character. Filename for the output RasterLayer (optional)

directions

Integer. Which cells are considered adjacent? Should be 8 (Queen's case) or 4 (Rook's case)

gaps

Logical. If TRUE (the default), there may be 'gaps' in the chunk numbers (e.g. you may have clumps with IDs 1, 2, 3 and 5, but not 4). If it is FALSE, these numbers will be recoded from 1 to n (4 in this example)

...

Additional arguments as for writeRaster

Value

RasterLayer

Note

This function requires that the igraph package is available.

Author(s)

Robert J. Hijmans and Jacob van Etten

Examples

r <- raster(ncols=12, nrows=12)
set.seed(0)
values(r) <- round(runif(ncell(r))*0.7 )
rc <- clump(r) 
freq(rc)
plot(rc)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.