Learn R Programming

raster (version 2.0-41)

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

## S3 method for class 'RasterLayer,missing':
layerize(x, classes=NULL, falseNA=FALSE, filename='', ...)

## S3 method for class '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 the list will be merged in a single data.frame
filename
character. Output filename (optional)
...
Additional arguments as for writeRaster

Value

  • RasterBrick

Examples

Run this code
r <- raster(nrow=36, ncol=72)
r[] <- round(runif(ncell(r))*5)
r[1:5] <- NA
b <- layerize(r)

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

Run the code above in your browser using DataLab