changeStack

0th

Percentile

Add or drop a layer

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.

Keywords
spatial
Usage
addLayer(x, ...) 
addFiles(x, rasterfiles, bands= rep(1, length(rasterfiles))) 
dropLayer(x, i)
Arguments
x
a RasterStack or RasterBrick object
...
Raster* objects or filenames (character)
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

raster

Aliases
  • addLayer
  • addLayer,RasterStack-method
  • addLayer,RasterBrick-method
  • addFiles
  • dropLayer
  • dropLayer,RasterStack-method
  • dropLayer,RasterBrick-method
Examples
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)
Documentation reproduced from package raster, version 1.0.0-1, License: GPL (>= 3)

Community examples

Looks like there are no examples yet.