Learn R Programming

terra (version 1.5-34)

serialize: serialize and saveRDS for SpatRaster and SpatVector

Description

serialize and saveRDS for SpatRaster and SpatVector. Note that these objects will first be "packed" with wrap, and after unserialize/readRDS they need to be unpacked with rast or vect.

Use of these functions is not recommended. Especially for SpatRaster it is generally much more efficient to use writeRaster and write, e.g., a GTiff file.

SpatRaster objects must have all values in memory (that is, the cell values are not in files) to be serialized. These functions use set.values to load values into memory if needed and if deemed possible given the amount of RAM available.

Usage

# S4 method for SpatRaster
saveRDS(object, file="", ascii = FALSE, version = NULL, compress=TRUE, refhook = NULL)

# S4 method for SpatVector saveRDS(object, file="", ascii = FALSE, version = NULL, compress=TRUE, refhook = NULL)

# S4 method for SpatRaster serialize(object, connection, ascii = FALSE, xdr = TRUE, version = NULL, refhook = NULL)

# S4 method for SpatVector serialize(object, connection, ascii = FALSE, xdr = TRUE, version = NULL, refhook = NULL)

Arguments

object

SpatVector or SpatRaster

file

file name to save object to

connection
ascii
version
compress
refhook
xdr

Value

Packed* object

Examples

Run this code
# NOT RUN {
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
p <- serialize(v, NULL)
head(p)
x <- unserialize(p)
x
vect(x)
# }

Run the code above in your browser using DataLab