nh_stack | R Documentation |
Takes a rastfiles
of binary raster's filenames (values 0/1),
a template raster covering the extent desired for the stack,
and optionally the codes
(names) to use
for the rasters. Returns a single raster layer (factor type with an
attribute table).
nh_stack(rastfiles, rast, codes = NULL, return.table = TRUE, clip.feat = NULL)
rastfiles |
raster file names; character vector |
rast |
raster template dataset |
codes |
species codes; character vector. If given, must match length of |
return.table |
Whether to return a table with nh_stack unique values, species codes, and filenames |
clip.feat |
sf data with masking features for rastfiles. Must have column named 'code', matching |
The raster attribute table (accessed using cats()
)
has four columns: 'ID': the unique integer value in the raster; 'VALUE':
the internal nh_stack unique value for that 'ID', 'ALLCODES': the
identity of species codes, pasted in a character vector seperated by ';',
'ALLCODES_CT': the number of unique codes for that value.
If codes
is not given, the raster layer name will be used as the
layer's code. If these are not unique, the internal nh_stack unique value will
be pasted to the end of the original code, and a message will be printed.
All rasters must have the same projection and resolution, though
they can have different extents - the processing extent is defined by
rast
. To summarize all rasters across their
entire extents, rast
should essentially be the union (mosaic)
of all raster extents.
When return.table
is TRUE, a list with two objects (1), the
stack raster, and (2) a summary table of included rasters is returned (with
internal nh_stack unique values, species codes, and file names). This table
is required for resampling the stack (i.e. with nh_stack_resample
).
SpatRaster
David Bucklin
## Not run:
rast <- rast("inputs/_masks/data_mask.tif")
list <- sort(list.files(paste0("proj_psh/thumb"), full.names = T, pattern = ".tif$"))
rastfiles <- c(list[sample(1:length(list), size=5)], "proj_psh/thumb/helevirg_10Aug2018.tif",
"proj_psh/thumb/myotsoda_10May2018.tif")
codes <- unlist(lapply(basename(rastfiles), function(x) strsplit(x, "_")[[1]][1]))
stack <- nh_stack(rastfiles, rast, codes = NULL)
# view raster attributes
cats(stack[[1]])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.