Marshalling of 'raster' objects

# S3 method for RasterLayer
marshal(x, ...)

# S3 method for RasterLayer
marshallable(x, ...)

Arguments

x

A raster:RasterLayer object.

...

Not used.

Value

A marshalled object as described in marshal().

Details

raster::writeRaster() is used to produce a marshalled version of the original object. raster::raster() is used to reconstruct a version of the original object from the marshalled object.

WARNING - Numerical identical results cannot be guaranteed

Marshalling of RasterLayer objects is leaky. More precisely, the method cannot guarantee that multiple rounds of marshalling and unmarshalling produce numerically identical objects. For further information, see (1).

References

  1. Issue #311 - 'Incorrect large values saved to disk with writeRaster()', raster GitHub repostory, 2023-05-17, https://github.com/rspatial/raster/issues/311.

Examples

if (requireNamespace("raster", quietly = TRUE)) {
  r <- raster::raster(system.file("external/test.grd", package = "raster"))
  print(r)
  
  ## Marshal
  r_ <- marshal(r)

  ## Unmarshal
  r2 <- unmarshal(r_)
  print(r2)
}
#> class      : RasterLayer 
#> dimensions : 115, 80, 9200  (nrow, ncol, ncell)
#> resolution : 40, 40  (x, y)
#> extent     : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
#> crs        : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +datum=WGS84 +units=m +no_defs 
#> source     : test.grd 
#> names      : test 
#> values     : 138.7071, 1736.058  (min, max)
#> 
#> class      : RasterLayer 
#> dimensions : 115, 80, 9200  (nrow, ncol, ncell)
#> resolution : 40, 40  (x, y)
#> extent     : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
#> crs        : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +datum=WGS84 +units=m +no_defs 
#> source     : file725b87cb086c7.grd 
#> names      : test 
#> values     : 139, 1736  (min, max)
#>