Use terra::WriteRaster() followed by rio cogeo create for creating cloud-optimized GeoTIFF that minimizes the output file size with creation options for maximum compression (COMPRESS=DEFLATE ZLEVEL=9 PREDICTOR=2), tiles (TILED=YES) (and optionally sparse (SPARSE_OK=TRUE) encoding).

write_rast(
  r,
  tif,
  datatype = NULL,
  overwrite = TRUE,
  method = c("average", "nearest"),
  threads = "ALL_CPUS",
  epsg = 3857,
  verbose = F,
  web_optimize = F,
  use_gdal_cog = F
)

Arguments

r

input raster layer or path to input GeoTIFF

tif

output path to GeoTIFF

datatype

datatype; one of: INT1U, INT2S, INT2U, INT4S, INT4U, FLT4S, FLT8S; default is NULL and datatype is automatically detected

overwrite

defaults to TRUE

method

for internal overview generation; use "average" (default) for continous and "nearest" for categorical

threads

used by rio cogeo create; defaults to "ALL_CPUS"; change to 1 if using in parallel

epsg

projection number; default: Web Mercator (3857)

verbose

show commands; defaults to FALSE

web_optimize

create a web-tiling friendly COG per Advanced Topics - rio-cogeo that aligns internal tiles with the web-mercator grid resulting in a larger

use_gdal_cog

use GDAL COG driver (requires GDAL >= 3.1); does not change extent file with different bounds and pixel sizes from original; defaults to FALSE

Value

returns nothing since only writing tif, i.e. a side-effect function

Details

The datatype corresponds with the following:

terraminmaxgdalrio
INT1U0255Byteuint8
INT2S-32,76732,767Int16int16
INT2U065,534UInt16uint16
INT4S-2,147,483,6472,147,483,647Int32int32
INT4U04,294,967,296UInt32uint32
FLT4S-3.4e+383.4e+38Float32float32
FLT8S-1.7e+3081.7e+308Float64float64