Skip to contents

This function processes a SpatRaster object or a file path to it, ensuring the raster is loaded and unpacked if necessary. It converts raster objects from the raster package to SpatRaster objects. The function ensures that the SpatRaster object is read from memory, not from file.

Usage

setRastVals(R)

Arguments

R

A SpatRaster object, a file path to a raster file, or an object from the raster package (e.g., RasterLayer, RasterStack, RasterBrick).

Value

A SpatRaster object with values loaded into memory.

Details

The function handles various types of input:

  • If a file path is provided, it attempts to load the raster using terra::rast().

  • If the input is a packed SpatRaster, it unpacks the raster using terra::unwrap().

  • If the input is a raster object from the raster package, it is converted to SpatRaster.

Author

Ahmed El-Gabbas