odcr classes to native spatial classesR/xarray_methods.R
    coerce-methods.Rdas.stars() allows to convert xarray.core.dataset.Dataset to stars.
as.raster() allows to convert xarray.core.dataset.Dataset to RasterLayer or RasterBrick.
as.stars(from) as.raster(from)
| from | object of class  | 
|---|
as.stars() retruns an object of class stars
as.raster() retruns an object of class RasterLayer or RasterBrick or a list of such in case of more than 3 dimensions
if (FALSE) { library(odcr) # connect to a database, store the Daatcube connection internally (default and recommended) database_connect(app = "Sentinel_2") # build a query list lat <- 22.821 lon <- 28.518 buffer <- 0.05 query <- list( 'time' = c('2020-01', '2020-03'), 'x' = c(lon - buffer, lon + buffer), 'y' = c(lat + buffer, lat - buffer), 'output_crs' = 'epsg:6933', 'resolution' = c(-20,20) ) # load data and return an xarray object for a query ds <- dc_load(query = c(product = "s2_l2a", dask_chunks = dict(), query)) ds <- ds[,101:300,101:300] # convert to stars (multi-dimensional and mulit-varariable) ds_stars <- as.stars(ds) ds_stars <- as(ds, "stars") # convert to stars (single variable) ds_stars <- as.stars(ds[[1]]) # convert to stars (2-dim, multi-variable) ds_stars <- as.stars(ds[1,,]) # convert to raster (multi-dimensional and mulit-varariable) ds_raster <- as.raster(ds) ds_raster <- as(ds, "raster") # raster cannot represent 4-dim objects, thus coereced to list of RasterBricks # convert to starasterrs (single variable) ds_raster <- as.raster(ds[[1]]) # convert to raster (2-dim, multi-variable) ds_raster <- as.raster(ds[1,,]) }