writeRST.Rd
Read and write rasters using the fst library
writeRST(x, filename = NULL, object = FALSE, ...)
importRST(x, layers = NULL, ...)
An object of class SpatRaster or Raster. It may not contain layers named 'x' or 'y'
Character. Output filename. Do not use extensions. If null, (the defaul), no file is saved
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
.
Character vector containing the names of the layers to import.
Default is layers = NULL
which imports all layers.
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
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)]
#> x y z
#> 1: 0.01 0.01 1.0146139
#> 2: 0.02 0.01 1.0404641
#> 3: 0.03 0.01 1.0675194
#> 4: 0.04 0.01 1.0958300
#> 5: 0.05 0.01 1.1254477
#> ---
#> 249996: 4.96 5.00 1.0711366
#> 249997: 4.97 5.00 1.0428260
#> 249998: 4.98 5.00 1.0157707
#> 249999: 4.99 5.00 0.9899205
#> 250000: 5.00 5.00 0.9652271
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"
writeRST(dem, 'DEM.fst')
importRST('DEM.fst')
#> class : SpatRaster
#> dimensions : 251, 251, 1 (nrow, ncol, nlyr)
#> resolution : 40, 40 (x, y)
#> extent : 9970, 20010, 29990, 40030 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=lcc +lat_0=0 +lon_0=-100 +lat_1=48 +lat_2=33 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
#> source(s) : memory
#> name : z
#> min value : 0.9652271
#> max value : 499.9750012