writeRST: Fast read and write rasters

View source: R/writeRST.R

writeRSTR Documentation

Fast read and write rasters

Description

Read and write rasters using the fst library

Usage

writeRST(x, filename = NULL, object = FALSE, ...)

importRST(x, layers = NULL, ...)

Arguments

x

An object of class SpatRaster or Raster. It may not contain layers named 'x' or 'y'

filename

Character. Output filename. Do not use extensions. If null, (the defaul), no file is saved

object

Logical. If true, function returns a data.table passable to importRST that will produce a valid raster (i.e. fixes rounding errors when using init. Default is FALSE.

...

Additional parameters to pass on to read_fst or write_fst

layers

Character vector containing the names of the layers to import. Default is layers = NULL which imports all layers.

Value

If object = TRUE, a data.table with an added $crs attribute containing the projection information. Special values are stored in the first three rows: (1) The x and y resolution (2) The x and y coordinates of the corner, and (3) The x and y coordinates of the rounding offset

Examples

 
n <- 5
dem <- expand.grid(list(x = 1:(n * 100),
                        y = 1:(n * 100))) / 100
dem <- as.data.table(dem)
dem[, z := 250 * exp(-(x - n/2)^2) + 
      250 * exp(-(y - n/2)^2)]
dem <- rast(dem)
ext(dem) <- c(10000, 20000, 30000, 40000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"

dir <- tempdir()

writeRST(dem, paste0(dir,'/DEM.fst'))
importRST(paste0(dir,'/DEM.fst'))

andresgmejiar/lbmech documentation built on Feb. 2, 2025, 12:37 a.m.