View source: R/extract_soils_POLARIS.R
extract_soils_POLARIS | R Documentation |
Extract soil information from the POLARIS soil dataset for SOILWAT2 applications
extract_soils_POLARIS(
x,
crs = 4326,
vars = c("bd", "sand", "clay", "silt"),
stat = "mean",
path = ".",
method = c("asis", "fix_with_buffer"),
fix_criteria = list(bd = list(op = "<", value = 0.6), texture = list(op = "<", value =
0.5)),
buffer_m = NULL,
fun = NULL,
na.rm = TRUE,
digits = 3L,
verbose = FALSE
)
x |
A numerical two-dimensional object
(a |
crs |
An object which is a crs or from which one can be derived.
|
vars |
A vector of character strings. See Chaney et al. 2019 |
stat |
A character string. See Chaney et al. 2019 |
path |
A character string. The path to the local copy of the
POLARIS folder hierarchy, e.g.,
|
method |
A character string. Method that determines extraction approach:
(i) values are extracted using arguments
|
fix_criteria |
A named list. Names correspond to |
buffer_m |
A numeric value. The radius of a buffer around each point
from which to extract cell values and across which |
fun |
A function if |
na.rm |
A logical value. Passed to |
digits |
An integer value. The number of digits to which soil texture
variables are rounded. Skip rounding if |
verbose |
A logical value. |
A local copy of POLARIS is required. The function
prepare_script_for_POLARIS
creates a script that can be used
to download POLARIS files.
POLARIS uses weight-based percent as unit for sand, clay, silt; values occur in 1 soil texture in units of weight-based fractions.
Chaney, N. W., B. Minasny, J. D. Herman, T. W. Nauman, C. Brungard, C. L. S. Morgan, A. B. McBratney, E. F. Wood, and Y. T. Yimam. 2019. POLARIS soil properties: 30-meter probabilistic maps of soil properties over the contiguous United States. Water Resources Research 55:2916-2938. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1029/2018WR022797")}.
extract
script_to_download_polaris <- prepare_script_for_POLARIS()
## Execute script to download data
## (or set `path_polaris` to your local copy)
path_polaris <- dirname(script_to_download_polaris)
vars <- c("bd", "sand", "clay", "silt")
stat <- "mean"
## Check that we have POLARIS data
has_POLARIS <- isTRUE(all(
check_POLARIS(path = path_polaris, vars = vars, stat = stat)
))
if (has_POLARIS) {
locations <- matrix(
data = c(-120.1286878, -111.8511136, 39.8182913, 36.9047396),
nrow = 2
)
## Extract median of mean gridcell values across 100-m buffer
## around point locations
res1 <- extract_soils_POLARIS(
x = locations,
vars = vars,
stat = stat,
path = path_polaris,
buffer_m = 100,
fun = median,
na.rm = TRUE
)
## Extract mean gridcell values at point locations and use 70-m buffer at
## sites with bad values
res2 <- extract_soils_POLARIS(
x = locations,
vars = vars,
stat = stat,
path = path_polaris,
method = "fix_with_buffer",
fix_criteria = list(
bd = list(op = "<", value = 0.6),
texture = list(op = "<", value = 50)
),
buffer_m = 70,
fun = list(
bd = function(x, na.rm = TRUE) median(x[x > 0.6], na.rm = na.rm),
texture = median
),
na.rm = TRUE,
digits = 3
)
}
# Clean up example
unlink(script_to_download_polaris)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.