pkern_export | R Documentation |
Convert column-vectorized grid to SpatRaster
pkern_export(g, template = "terra")
g |
any object accepted or returned by |
template |
character or RasterLayer/SpatRaster to set output type Converts a column-vectorized vector or matrix to a SpatRaster, or if terra is unavailable, a RasterLayer. |
a RasterLayer or SpatRaster containing the data from g
(or a sub-grid)
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 = pkern_grid(r)
# convert back to RasterLayer and compare
r_from_g = pkern_export(g, 'raster')
print(r_from_g)
print(r)
# 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 = pkern_grid(r)
r_from_g = pkern_export(g)
# 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.