extract_soils_SOLUS100: Extract soil information from the 'SOLUS100' soil dataset for...

View source: R/extract_soils_NRCS_SOLUS100.R

extract_soils_SOLUS100R Documentation

Extract soil information from the SOLUS100 soil dataset for SOILWAT2 applications

Description

Extract soil information from the SOLUS100 soil dataset for SOILWAT2 applications

Usage

extract_soils_SOLUS100(
  x,
  crs = 4326,
  vars = c("dbovendry", "fragvol", "sandtotal", "silttotal", "claytotal", "soc"),
  var_depth = "resdept_cm",
  depths = depth_profile_SOLUS100(),
  stat = c("p", "l", "h", "rpi"),
  path = ".",
  method_vertical = c("asis", "interpolate_by_layer"),
  requested_layer_depths = NULL,
  method_horizontal = c("asis", "fix_with_buffer"),
  fix_criteria = list(dbovendry = list(op = "<", value = 0.6), texture = list(op = "<",
    value = 0.5)),
  buffer_m = NULL,
  fun = NULL,
  na.rm = TRUE,
  digits = 3L,
  verbose = FALSE
)

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.

vars

A vector of variable names. See variables_SOLUS100()

var_depth

A character string or NULL. If NULL, then soil depth is determined based on (i) available data layers depths (up to 201 cm; see Nauman et al. 2024), (ii) depth of non-missing values in extracted vars (which may be 0). Otherwise, soil depth is the extracted value of the SOLUS100 variable var_depth. Soil depth is set to 0 if is missing or all vars values are missing.

depths

Soil depths in centimeters from surface. See depth_profile_SOLUS100()

stat

A vector of character strings. See Nauman et al. 2024

path

A character string. The path to the local copy of SOLUS100.

method_vertical

A character string that is "asis" or "interpolate_by_layer": (i) method "asis" extracts the values as provided by SOLUS100, i.e., as point estimates at specified depths (ii) method "interpolate_by_layer" interpolates extracted values for each centimeter depth increment and averages the interpolated values across requested soil layers (see requested_layer_depths). Soils properties for a soil with a missing depth value or a depth of less than 1 centimeter are set to NA.

requested_layer_depths

An integer vector (used if method_vertical = "interpolate_by_layer"). Soil depths (in centimeters) at lower layer boundaries used for output If NULL, then layer boundaries are assumed to be c(depths, 201).

method_horizontal

A character string. Method that determines the extraction approach across grid cells: (i) values are extracted using arguments buffer_m, fun, and na.rm and are returned "asis" or (ii) values are extracted for point locations, i.e., temporarily setting buffer_m = NULL; then, sites with problematic values (as determined by fix_criteria) are extracted again under "fix_with_buffer" based on buffer_m, fun, and na.rm

fix_criteria

A named list (used if method_horizontal = "fix_with_buffer"). Names match values of vars or one of the names can be "texture" (in which case the criterion is applied to sand, clay, and silt). Each element is applied to the variable that corresponds to the name and is used to determine whether a site has problematic values. Elements themselves are a named list with two sub-elements "op" for the relationship operator, e.g., "<", and "value" for the value to compare against. See examples.

buffer_m

A numeric value. The radius of a buffer around each point from which to extract cell values and across which fun is applied. Set to NULL to extract SOLUS100 gridcell values at point locations.

fun

A function or a named list containing functions (used if method_horizontal = "fix_with_buffer"). Names match values of vars or one of the names can be "texture" (in which case the criterion is applied to sand, clay, and silt). The function(s) summarize(s) extracted values if more than one value is extracted per location (based on buffer_m).

na.rm

A logical value. Passed to fun.

digits

An integer value. The number of digits to which soil texture variables are rounded. Skip rounding if NA or NULL.

verbose

A logical value.

Notes

A local copy of SOLUS100 is required. The function download_SOLUS100() can be used to download SOLUS100 files.

References

Nauman, T. 2024. Data from: Soil Landscapes of the United States 100-meter (SOLUS100) soil property maps project repository. Ag Data Commons. https://doi.org/10.15482/USDA.ADC/25033856.V1.

See Also

terra::extract()

Examples

## Not run: 
if (curl::has_internet()) {
path_solus100 <- tempdir()
req_vars <- c("resdept_cm", "sandtotal")
req_depths <- 0

## Download data
fns_solus100 <- rSW2exter::download_SOLUS100(
  path = path_solus100,
  vars = req_vars,
  depths = req_depths
)

## Check that we have SOLUS100 data
has_SOLUS100 <- isTRUE(all(
  check_SOLUS100(
    path = path_solus100,
    vars = req_vars,
    depths = req_depths
  )
))

if (has_SOLUS100) {
  locations <- matrix(
    data = c(-120.1286878, -111.8511136, 39.8182913, 36.9047396),
    nrow = 2
  )

  ## Extract gridcell values at point locations
  res <- extract_soils_SOLUS100(
    x = locations,
    vars = req_vars,
    depths = req_depths,
    path = path_solus100
  )
}

# Clean up example
unlink(file.path(path_solus100, fns_solus100))
}

## End(Not run)


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