extract_topography_NEDUSA: Extract elevation, slope, and aspect from National Elevation...

View source: R/extract_topography_NEDUSA.R

extract_topography_NEDUSAR Documentation

Extract elevation, slope, and aspect from National Elevation Dataset NED for SOILWAT2 applications

Description

Extract elevation, slope, and aspect from National Elevation Dataset NED for SOILWAT2 applications

Usage

extract_topography_NEDUSA(
  x,
  crs = 4326,
  path = ".",
  file_datasets = list(elev = "ned_1s.tif", slope = file.path("terrain",
    "slope_ned_1s.tif"), aspect = file.path("terrain", "aspect_ned_1s.tif")),
  units_slope = c("degrees", "radians"),
  units_aspect = c("degrees", "radians"),
  south_aspect = c(180, 0),
  method = "simple",
  flat_lt_slope = 0
)

Arguments

x

A numerical two-dimensional object (a matrix, array, or data.frame) with longitude/X, latitude/Y as columns; a sp::SpatialPoints object; or a terra::SpatVector object; or a sf object with a point geometry, i.e., an object with a class sf or sfc.

crs

An object which is a crs or from which one can be derived. x can be numeric as a EPSG number; a character string as a wkt; a character string as a proj4 (not recommended because outdated); or of a class including raster::Raster, sp::Spatial, sp::CRS, or a sf or sfc class.

path

A character string. The path to the folder containing NED-1arcsec files, see file_datasets.

file_datasets

A named list. The paths/filenames of the NED files relative to path. The names are "elev", "slope", and "aspect". At least one must exists.

units_slope

A character string. "degrees" or "radians".

units_aspect

A character string. "degrees" or "radians".

south_aspect

An integer value. The value indicating a south aspect in degrees, either 0 or 180 degrees. See details.

method

A character string passed to extract.

flat_lt_slope

A numeric value. Slope values less than flat_lt_slope are set to 0 and aspect values to NA; units are the same as the slope dataset.

Value

A data.frame with one row per locations and up to three columns named like the elements of existing file_datasets, i.e., "elev" in units [m a.s.l.], "slope" in units [0 - 90 degree], and "aspect" in units [degree; South = 0, E = -90, N = ±180, W = 90; no aspect = NA].

Details

The raster values are expected to be in units of [m a.s.l.] for elevation, degrees or radians for slope with a range of [0 - 90 degree] or [0 - pi/2], and degrees or radians for aspect with an orientation of either [North = 0 = 360, E = 90, S = 180, W = 270] and no aspect indicated by one of {NA, 999, < 0} or [South = 0, E = -90, N = ±180, W = 90] and no aspect indicated by one of {NA, 999}, or respectively in radians.

Notes

First, obtain NED, e.g., via get_ned; then, derive slope and aspect, e.g., via terrain and make sure that gridcells without aspect are correctly encoded. Please, note that get_ned downloads tiles in a temporary folder and returns a mosaic-ed file; this can be slow for large spatial extents. Preferably, download tiles to a local folder and build a vrt across the tiles.

Examples

## Not run: 
if (requireNamespace("FedData") && curl::has_internet()) {
  label_ned <- "ned_1s_example"
  path_ned <- "."
  filenames_ned_examples <- list(
    elev = paste0(label_ned, "_NED_1.tif"),
    slope = paste0("slope_", label_ned, "_NED_1.tif"),
    aspect = paste0("aspect_", label_ned, "_NED_1.tif")
  )

  locations <- rSW2st::as_points(
    matrix(data = c(-120.34, -120.33, 43.23, 43.24), nrow = 2),
    to_class = "sf",
    crs = 4326
  )
  extent_polygon <- terra::vect(
    1.1 * terra::ext(locations),
    crs = terra::crs(locations)
  )

  ### Download NED
  ned_1s_example <- FedData::get_ned(
    template = extent_polygon,
    label = label_ned,
    res = 1,
    extraction.dir = path_ned
  )

  ### Derive slope and aspect
  for (opt in c("slope", "aspect")) {
    tmp <- terra::terrain(
      x = ned_1s_example,
      v = opt,
      unit = "degrees",
      filename = filenames_ned_examples[[opt]]
    )
  }

  ### Get values
  vals_topo <- extract_topography_NEDUSA(
    locations,
    path = path_ned,
    file_datasets = filenames_ned_examples,
    south_aspect = 180,
    method = "simple"
  )

  # Fix column names for output
  cns <- c(elev = "ELEV_m", slope = "Slope_deg", aspect = "Aspect_deg")
  colnames(vals_topo) <- cns[colnames(vals_topo)]
  vals_topo

  ### Get elevation values
  vals_elev <- extract_topography_NEDUSA(
    locations,
    path = path_ned,
    file_datasets = filenames_ned_examples["elev"],
    south_aspect = 180,
    method = "simple"
  )

  # Clean up
  unlink(file.path(path_ned, unlist(filenames_ned_examples)))
}

## End(Not run)


DrylandEcology/rSW2exter documentation built on May 4, 2024, 10:53 p.m.