fetch_soils_from_NRCS_SDA: Download soil data from 'NRCS' 'SDA' web service

View source: R/extract_soils_NRCS_SDA.R

fetch_soils_from_NRCS_SDAR Documentation

Download soil data from NRCS SDA web service

Description

Download soil data from NRCS SDA web service

Usage

fetch_soils_from_NRCS_SDA(
  mukeys_unique,
  bind_params = mukeys_unique,
  sql_template = NA,
  injection_format = "mukey IN (%s)",
  majcompflag = c("subset", "ignore"),
  only_soilcomp = TRUE,
  chunk_size = 1000L,
  progress_bar = FALSE
)

Arguments

mukeys_unique

An integer vector with unique mukey values. Deprecated; use bind_params instead.

bind_params

A vector or 2-dimensional container with parameter values to bind to the T-SQL query via injection_format.

sql_template

A character vector. A valid T-SQL query with a "WHERE" clause so that the code can inject chunks of bind_params values via format injection_format. If NA, then the default query is loaded, see examples.

injection_format

A character vector that identifies the location (format specifier) in sql_template for parameter value injection/binding.

majcompflag

A character string. "subset" keeps the "WHERE" clause component.majcompflag = 'Yes' that is contained in sql_template; "ignore" removes it from the query. Note that the field "majcompflag" exists only in the SSURGO version of the "component" table, but not in the STATSGO version.

only_soilcomp

A logical value. If TRUE, then query restricts to soil components. If FALSE, then query includes all components including "Miscellaneous areas" and "NOTCOM" (not complete) components.

chunk_size

An integer value. The size of chunks into which bind_params is broken up and looped over for processing.

progress_bar

A logical value. Display a progress bar as the code loops over the chunks?

Value

A data.frame according to the specifications of sql or NULL if the query returns empty.

Notes

A live internet connection is required to access SDA.

This is a function with minimal functionality; use extract_soils_NRCS_SDA() for a user-friendly interface.

See Also

soilDB::SDA_query()

Examples

## Not run: 
if (curl::has_internet()) {
  # Query soils of dominant component of soil map unit
  fetch_soils_from_NRCS_SDA(bind_params = 67616)

  # As of 2022-March-15, mukey 2479921 contained one "NOTCOM" component
  fetch_soils_from_NRCS_SDA(bind_params = 2479921)
  fetch_soils_from_NRCS_SDA(bind_params = 2479921, only_soilcomp = FALSE)

  sql <- readLines(
    system.file("NRCS", "nrcs_sql_template.sql", package = "rSW2exter")
  )

  fetch_soils_from_NRCS_SDA(bind_params = 67616, sql_template = sql)

  # This will return NULL because -1 is not an existing mukey value
  fetch_soils_from_NRCS_SDA(bind_params = -1, sql_template = sql)

  # Query soils of a specific component of a soil map unit
  sql2 <- readLines(
    system.file("NRCS", "nrcs_sql_template2.sql", package = "rSW2exter")
  )

  fetch_soils_from_NRCS_SDA(
    bind_params = data.frame(mukey = 398856, compname = "Waupaca"),
    sql_template = sql2,
    injection_format = "(VALUES %s) AS t (mm, cn)"
  )
}

## End(Not run)


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