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
)input raster layer or path to input GeoTIFF
output path to GeoTIFF
datatype; one of: INT1U, INT2S, INT2U, INT4S, INT4U, FLT4S, FLT8S; default is NULL and datatype is automatically detected
defaults to TRUE
for internal overview generation; use "average" (default) for continous
and "nearest" for categorical
used by rio cogeo create; defaults to "ALL_CPUS"; change to 1 if using in parallel
projection number; default: Web Mercator (3857)
show commands; defaults to FALSE
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 driver (requires GDAL >= 3.1); does not change extent file with different bounds and pixel sizes from original; defaults to FALSE
returns nothing since only writing tif, i.e. a side-effect function
The datatype corresponds with the following:
| terra | min | max | gdal | rio |
| INT1U | 0 | 255 | Byte | uint8 |
| INT2S | -32,767 | 32,767 | Int16 | int16 |
| INT2U | 0 | 65,534 | UInt16 | uint16 |
| INT4S | -2,147,483,647 | 2,147,483,647 | Int32 | int32 |
| INT4U | 0 | 4,294,967,296 | UInt32 | uint32 |
| FLT4S | -3.4e+38 | 3.4e+38 | Float32 | float32 |
| FLT8S | -1.7e+308 | 1.7e+308 | Float64 | float64 |