opendata_bc {rasterbc}R Documentation

Load/merge data blocks and optionally clip/mask them

Description

Loads all mapsheets covering the geographical extent of input argument geo. This can be a vector of (4-character) NTS/SNRC block codes, or a geometry of class sfc having a defined coordinate reference system.

Usage

opendata_bc(
  geo = NULL,
  collection = NULL,
  varname = NULL,
  year = NULL,
  type = "mask",
  quiet = FALSE,
  dl = TRUE
)

Arguments

geo

vector of character strings (NTS/SNRC codes) or a geometry of class sfc

collection

character string, indicating the data collection to query

varname

character string, indicating the layer to query

year

integer, indicating the year to query

type

character string, one of 'all', 'clip', 'mask'

quiet

logical, suppresses console messages

dl

logical, enables automatic downloading of missing files

Details

Data for the layer specified by collection, varname, and (as needed) year, are fetched from the directory specified by datadir_bc, merged into a single (mosaic) layer, cropped and masked as needed, and then loaded into memory and returned as a SpatRaster object. If the files are not found, and dl=TRUE, they will be automatically downloaded.

When geo is a line or point type geometry (or when type='all'), the function uses terra::merge to create a larger (mosaic) SpatRaster containing the data from all mapsheets intersecting with the input extent.

When geo is a polygon, type can be set to clip or mask the returned raster: 'all' returns the mosaic, as above; 'clip' crops the mosaic and to the bounding box of geo; and 'mask' (the default) crops the mosaic then sets all points not lying inside geo to NA. Note that type is ignored when geo is a point geometry or a character string of codes (these cases behave like type='all').

Value

A SpatRaster

Examples

# define a location of interest, and a circle of radius 10km around it
input.point = sf::st_point(c(x=-120.1, y=50.1)) |> sf::st_sfc(crs='EPSG:4326')

if( requireNamespace('units', quietly = TRUE) ) {
input.polygon = input.point |> sf::st_buffer(units::set_units(10, km))

## Not run: 
# the following downloads data from FRDR
# open the DEM mapsheets corresponding to the polygon and plot
opendata_bc(geo=input.polygon, 'dem') |> terra::plot()

## End(Not run)
}

[Package rasterbc version 1.0.2 Index]