raster (version 1.4-10)

changeStack: Add or drop a layer

Description

Add or drop a layer to a RasterStack or RasterBrick. A RasterStack is a collection of RasterLayers with the same spatial extent and resolution. A RasterBrick is a multi-layer object. With these functions, you can add RasterLayers to, or remove RasterLayers from, a RasterStack or RasterBrick object.

Usage

addLayer(x, ...) 
addFiles(x, rasterfiles, bands= rep(1, length(rasterfiles))) 
dropLayer(x, i, ...)

Arguments

x
a RasterStack or RasterBrick object
...
addLayer: Raster* objects or filenames (character); dropLayer: a filename and other file writing options if x is a RasterBrick
rasterfiles
Filename(s) of (a) raster dataset(s)
bands
a vector or list of bands of raster data files (default values = 1)
i
a vector of the indices of the layer(s) to remove from a RasterStack

Value

  • a RasterStack object

See Also

subset

Examples

Run this code
rasterfile <- system.file("external/test.grd", package="raster")
  st <- stack(rasterfile)
# now adding the same file multiple times, in most cases you would add different files  
# this generates warnings, but it is not an error
  st <- addFiles(st, c(rasterfile, rasterfile))
  rs <- raster(rasterfile)
  st <- addLayer(st, c(rs, rs))
  st
  st <- dropLayer(st, c(3, 5))
  nlayers(st)

Run the code above in your browser using DataLab