Skip to contents

Create an R object representing an SDP dataset.

Usage

sdp_get_raster(
  catalog_id = NULL,
  url = NULL,
  years = NULL,
  months = NULL,
  date_start = NULL,
  date_end = NULL,
  verbose = TRUE,
  download_files = FALSE,
  download_path = NULL,
  overwrite = FALSE,
  ...
)

Arguments

catalog_id

character. A single valid catalog number for an SDP dataset. This is in the CatalogID field for information returned by sdp_get_catalog().

url

character. A valid URL (e.g. https://path.to.dataset.tif) for the cloud-based dataset. You should specify either catalog_id or url, but not both.

years

numeric. For annual time-series data, a numeric vector specifying which years to return. The default NULL returns all available years.

months

numeric. For monthly time-series data, a numeric vector specifying which months of data to return. The default NULL returns all available months.

date_start

class Date. For daily time-series data, the first day of data to return.

date_end

class Date. For daily time-series data, the last day of data to return.

verbose

logical. Should the function print status and progress messages?

download_files

logical. Should the function download files to disk? The default FALSE creates cloud-based representations of the data without downloading.

download_path

character. Destination path for downloaded files. This can be a relative or absolute path.

overwrite

logical. Should files with the same names as the datasets be overwritten in download_path? If FALSE, the function will skip downloading files that already exist in the destination.

...

Other arguments to pass to the terra::rast() function.

Value

An R object (class terra::SpatRaster) representing the raster dataset.

Details

Files headers are read from cloud-based datasets using the terra package, but the full dataset is not downloaded locally unless download_files=TRUE. Instead terra uses the web-based file system embedded in GDAL (VSICURL) to access datasets on the cloud. For large datasets and slow network connections, the function might take up to a minute to complete. Specifying local downloads download_files=TRUE might be more efficient for multi-layer data, but can take up lots of disk space.

Examples

## Lookup catalog number for a dataset.
cat <- sdp_get_catalog(domain='UG',type='Vegetation')
lc_id <- cat$CatalogID[cat$Product=='Basic Landcover']

## Connect to the dataset without downloading
landcover <- sdp_get_raster(lc_id)
landcover
#> class       : SpatRaster 
#> dimensions  : 72603, 83004, 1  (nrow, ncol, nlyr)
#> resolution  : 1, 1  (x, y)
#> extent      : 305082, 388086, 4256064, 4328667  (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 84 / UTM zone 13N (EPSG:32613) 
#> source      : UG_landcover_1m_v4.tif 
#> color table : 1 
#> name        : UG_landcover_1m_v4