sk_export | R Documentation |
Convert "sk" grid to SpatRaster
sk_export(g, template = "terra")
g |
any object accepted or returned by |
template |
character or RasterLayer/SpatRaster to set output type Converts a vector or matrix to a SpatRaster or RasterLayer. Multi-layer outputs are supported for terra but not raster. |
a RasterLayer or SpatRaster containing the data from g
(or a sub-grid)
sk
Other exporting functions:
sk_coords()
if( requireNamespace('raster') ) {
# open example file as RasterLayer
r_path = system.file('external/rlogo.grd', package='raster')
r = raster::raster(r_path, band=1)
g = sk(r)
# convert back to RasterLayer and compare
r_from_g = sk_export(g, 'raster')
print(r)
print(r_from_g)
# NOTE: layer name, band number, and various other metadata are lost
all.equal(r_from_g, r)
}
# same with terra
if( requireNamespace('terra') ) {
# convert all layers
r = terra::rast(r_path)
g = sk(r)
r_from_g = sk_export(g)
# NOTE: various metadata are lost
all.equal(r_from_g, r)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.