getEnv: Download and extract environmental data for known locations.

View source: R/getEnv.R

getEnvR Documentation

Download and extract environmental data for known locations.

Description

Get environmental variables from trusted, global datasets, and optionally extract it for point locations

Usage

getEnv(
  region = NULL,
  locs = NULL,
  x = "x",
  y = "y",
  dem = NULL,
  proj = NULL,
  z_fix = NULL,
  zoom = 10,
  z_min = 0,
  filt = 0,
  slope = FALSE,
  twi = FALSE,
  depth = FALSE,
  soils = NULL,
  climate = NULL,
  acc = 15,
  vars = NULL,
  overwrite = FALSE,
  dir = tempdir(),
  ...
)

Arguments

region

A SpatRaster, Raster*, SpatVector, Spatial* or character string representing the area of interest. Required unless locs are provided. If region = NULL but locs are provided, then region = ext(locs).

locs

(Optional) A data.frame or something coercible to a data.table containing all observations to which data should be extracted.

x

A character string representing the data column containing the 'x' coordinates in meters or degrees. Ignored if data is of class SpatVector or Spatial.

y

A character string representing the data column containing the 'y' coordinates in meters or degrees. Ignored if data is of class SpatVector or Spatial, and ignored for distance calculations if dl is provided.

dem

(Optional) A SpatRaster or Raster object to use for slope and topographic wetness calculations. Default is dem = NULL, which will download the appropriate SRTM data using get_elev_raster(z = zoom)

proj

A crs object or character string representing the projection information for x,y coordinates. If z_fix is provided, default is for proj = z_fix. Ignored if locs if locs is SpatVector or Spatial. If locs is a data.table or data.frame and proj = NULL, the function will attempt proj = crs(dem) as a last resort.

z_fix

A raster with the origin, projection, and resolution of the desired output rasters.

zoom

Considered only if dem = NULL The zoom level to be downloaded. See documentation for the z parameter in get_elev_raster for further information.

z_min

The minimum allowable elevation. Useful if DEM source includes ocean bathymetry as does the SRTM data from AWS. Default is z_min = 0, but set to NULL to disable.

filt

Numeric. Size of moving window to apply a low-pass filter to terrain-based metrics (slope VIA DEM, twi directly)

slope

Logical. Should the slope at each input location be calculated? Default uses SRTM data from get_elev_raster, but this can be overwritten by providing a dem

twi

Logical. Should the topgraphic wetness index be calculated? Default uses the provided dem as a slope source, and HydroSHEDS 15s arcsecond data as a flow accumulation source, however this can be altered by modifying the acc parameter. All data are corrected for geodesic distorsion, which can be time-consuming if acc = 3

depth

Logical. Should the depth to bedrock be obtained? If TRUE, SoilGrids v. 1.0 data are downloaded from ISRIC SoilGrids. Unfortunately, these data are only provided globally and therefore the download is 1.34 GB.

soils

A character vector containing zero, all or, some of c('sand','silt','clay','cec','soc') representing soil's parts per million sand, silt, and clay content, the cation exchange capacity, and the organic carbon (respectively). Data are downloaded from ISRIC SoilGrids using their OGC Web Service API allowing the download to be fairly efficient.

climate

A character vector containing zero, all or, some of c("tmin","tavg","tmax","prec","srad") representing the minimum average temperature, average temperature, maximum average temperature, precipitation, and solar radiation. Data are downloaded from WorldClim v. 2 using worldclim_country.

acc

One of (1) A Raster or SpatRaster representing the flow accumulation in units of incoming per cell, or (2) an integer equal to one of acc = c(3, 15, 30), representing the resolution in arcseconds to download from HydroSHEDS. Default is acc = 15. Note that the 3s data is 2.29 GB.

vars

A SpatRaster object (or something coercible to it using the rast function) of one or multiple layers containing custom environmental data. Data with names equivalent to a parameter that has been activated will be ignored.

overwrite

Should the

dir

A filepath to the directory being used as the workspace. Default is tempdir() but unless the analyses will only be performed a few times it is highly recommended to define a permanent workspace so that files only need to be downloaded once.

...

Additional parameters to pass to fix_z.

Value

A folder in the 'dir' with the requested datasets.

Examples


# Get coordinates for Mexico City in longlat
data <- data.table(x = -99.1332,
                   y = 19.4326)

## Not run due to size of downloads
# getEnv(data, filt = 3)

andresgmejiar/lbmech documentation built on Feb. 2, 2025, 12:37 a.m.