write_caim: Write canopy image

View source: R/write_caim.R

write_caimR Documentation

Write canopy image

Description

Wrapper around terra::writeRaster() that writes a canopy image as GeoTIFF with 8- or 16-bit unsigned integers, setting CRS and extent.

Usage

write_caim(caim, path, bit_depth)

Arguments

caim

terra::SpatRaster.

path

character vector of length one. Destination file path (extension .tif will be enforced).

bit_depth

numeric vector of length one. Either 8 or 16.

Details

Adds the .tif extension to path if missing. The CRS is set to EPSG:7589 and the extent to ⁠[0, ncol] × [0, nrow]⁠ in pixel units. Data are written as INT1U when bit_depth = 8 and INT2U when bit_depth = 16.

Value

No return value. Called for side effects.

Examples

## Not run: 
caim <- read_caim() %>% normalize_minmax(0, 255)
write_caim(caim * (2^8 - 1),  file.path(tempdir(), "test_8bit"),  8)
write_caim(caim * (2^16 - 1), file.path(tempdir(), "test_16bit"), 16)
# Note: values are scaled by (2^bit_depth - 1) to avoid the maximum bin,
# which read_caim() might turn NA.

## End(Not run)

rcaiman documentation built on Sept. 9, 2025, 5:42 p.m.