Skip to contents

Saves a terra SpatRaster as a Cloud-Optimized GeoTIFF (COG) under the cog/ sub-directory of the dataset root. The variable must be listed in pgvariables. Layer names, time(), and units() are preserved natively inside the .tif. Plot metadata from pgvariables (label, unit, transform, plot_type) is stamped as pg_* GDAL metatags so the COG is self-describing. In addition, pg_colormap (derived from plot_type), pg_value_min, pg_value_max, pg_value_mean, pg_value_std (computed from the raster at save time), and — for discrete variables — pg_nunique and pg_class_values are also stamped. value_*, nunique, and class_values are computed from the raster at save time; colormap is derived from plot_type. These map directly onto rio-tiler/TiTiler rescale and colormap_name.

Usage

save_pgvariable(rast, varname, save_to = pgout_path())

Arguments

rast

Terra SpatRaster object from a gen_*() function.

varname

Character string with the variable name (must exist in pgvariables).

save_to

Character string with the dataset root path. Defaults to current custom data location based on config.

Value

NULL (invisibly). Called for side effects (saving file).

Examples

if (FALSE) { # \dontrun{
  r <- gen_ne_disputed_area_share()
  save_pgvariable(r, "ne_disputed_area_share")
} # }