Initial functions for a somewhat more formal approach to get or set z values (e.g. time) associated with layers of Raster* objects. In development.

setZ(x, z, name='time')
getZ(x)

Arguments

x

Raster* object

z

vector of z values of any type (e.g. of class 'Date')

name

character label

Value

setZ: Raster* object

getZ: vector

Examples

r <- raster(ncol=10, nrow=10)
s <- stack(lapply(1:3, function(x) setValues(r, runif(ncell(r)))))
s <- setZ(s, as.Date('2000-1-1') + 0:2)
s
#> class      : RasterStack 
#> dimensions : 10, 10, 100, 3  (nrow, ncol, ncell, nlayers)
#> resolution : 36, 18  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> names      :      layer.1,      layer.2,      layer.3 
#> min values : 0.0180922633, 0.0172559638, 0.0005705222 
#> max values :    0.9806570,    0.9771867,    0.9857181 
#> time        : 2000-01-01, 2000-01-02, 2000-01-03 
#> 
getZ(s)
#> [1] "2000-01-01" "2000-01-02" "2000-01-03"