Learn R Programming

aqp (version 0.99-8.56)

SDA_query: Soil Data Access Query

Description

Submit a query to the Soil Data Acccess (SDA) website in SQL, get the results as a dataframe.

Usage

SDA_query(q)

Arguments

q
a text string containing valid SQL

Value

  • A dataframe containing the results.

Details

The SDA website can be found at http://sdmdataaccess.nrcs.usda.gov.

References

http://casoilresource.lawr.ucdavis.edu/

See Also

MUKEYS_by_ll_bbox, mapunit_geom_by_ll_bbox

Examples

Run this code
# NASIS export metadata:
res <- SDA_query('select areasymbol, exportcertdate from distlegendmd order by areasymbol')
res$exportcertdate <- as.Date(as.POSIXct(res$exportcertdate, format='%m/%d/%Y %H:%M:%S'))
recently_updated <- res$areasymbol[res$exportcertdate > as.Date('2011-01-01')]

# basic query:
res <- SDA_query("select cokey, compname, comppct_r from component where compname = 'yolo' and majcompflag = 'Yes' ")

# get tabular data based on result from spatial query:
# bbox
b <- c(-120.9,37.7,-120.8,37.8)
# get map unit keys for this bbox
m <- MUKEYS_by_ll_bbox(b)
# make an SQL-compliant "in" statment
in.statement <- format_SQL_in_statement(m)
# format query:
q <- paste("SELECT component.cokey, compname, comppct_r, hzdept_r, hzdepb_r, hzname, sandtotal_r, silttotal_r, claytotal_r
FROM component JOIN chorizon ON component.cokey = chorizon.cokey
WHERE majcompflag = 'Yes' AND mukey IN ", in.statement, "ORDER BY cokey, comppct_r DESC, hzdept_r ASC", sep="")
# now get component and horizon-level data for these map unit keys
res <- SDA_query(q)

Run the code above in your browser using DataLab