This function is a simple wrapper around terra:writeRaster() that makes it easier to separate the individual layers of an input or output grid as separate files.

writeRasterLayers(x, output_dir = NULL, ...)

Arguments

x

character. Path to raster file(s) to split by layer.

output_dir

character. Default: NULL creates new directories in current working directory. Alternately specify a different path for output folders to be created.

...

Additional arguments to terra::writeRaster().

Value

New directories are created in output_dir (or current working directory) based on each input file x.

Examples

library(terra)

x <- writeRaster(rast(list(a = rast(matrix(1)), 
                           b = rast(matrix(2)))), "test.tif")

writeRasterLayers("test.tif", "test")

unlink(c("test.tif", "test"), recursive=TRUE)