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

layerize

Layerize


Description

Create a RasterBrick with a Boolean layer for each class (value, or subset of the values) in a RasterLayer. For example, if the cell values of a RasterLayer indicate what vegetation type they are, this function will create a layer (presence/absence; dummy variable) for each of these classes. Classes and cell values are always truncated to integers.

You can supply a second spatially overlapping RasterLayer with larger cells (do not use smaller cells!). In this case the cell values are counts for each class. A similar result might be obtained more efficiently by using layerize with a single RasterLayer followed by aggregate(x, , sum).

Usage

## S4 method for signature 'RasterLayer,missing'
layerize(x, classes=NULL, falseNA=FALSE, filename='', ...)

## S4 method for signature 'RasterLayer,RasterLayer'
layerize(x, y, classes=NULL, filename='', ...)

Arguments

x

RasterLayer

y

RasterLayer or missing

classes

numeric. The values (classes) for which layers should be made. If NULL all classes are used

falseNA

logical. If TRUE, cells that are not of the class represented by a layer are NA rather then FALSE

filename

character. Output filename (optional)

...

Additional arguments as for writeRaster

Value

RasterBrick

Examples

r <- raster(nrow=20, ncol=20)
values(r) <- c(rep(NA, 50), rep(1:5, 70))
b <- layerize(r)

r2 <- raster(nrow=5, ncol=5)
b2 <- layerize(r, r2)

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.