SDA_query {soilDB}R Documentation

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 valid T-SQL query surrounded by double quotes

Details

The SDA website can be found at http://sdmdataaccess.nrcs.usda.gov and query examples can be found at http://sdmdataaccess.nrcs.usda.gov/QueryHelp.aspx

Value

A dataframe containing the results. NULL is retutned when queries result in 0 matches rows.

Note

This function requires the 'httr', 'jsonlite', and 'XML' packages

Author(s)

D.E. Beaudette

See Also

mapunit_geom_by_ll_bbox

Examples

# SSURGO export metadata:
## Not run: 
##D q <- "SELECT areasymbol, saverest FROM sacatalog WHERE areasymbol LIKE 'CA%';"
##D x <- SDA_query(q)
##D x$saverest <- as.Date(x$saverest, format="%m/%d/%Y")
##D head(x)
## End(Not run)

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

# get component-level data for a specific soil survey area (Yolo county, CA)
## Not run: 
##D q <- "SELECT 
##D component.mukey, cokey, comppct_r, compname, taxclname, 
##D taxorder, taxsuborder, taxgrtgroup, taxsubgrp
##D FROM legend
##D INNER JOIN mapunit ON mapunit.lkey = legend.lkey
##D LEFT OUTER JOIN component ON component.mukey = mapunit.mukey
##D WHERE legend.areasymbol = 'CA113'"
##D 
##D res <- SDA_query(q)
## End(Not run)

# get tabular data based on result from spatial query:
# requires raster and rgeos packages
## Not run: 
##D library(raster) # suggested by soilDB
##D library(rgeos)  # additional
##D 
##D # text -> bbox -> WKT
##D # xmin, xmax, ymin, ymax
##D b <- c(-120.9, -120.8, 37.7, 37.8)
##D p <- writeWKT(as(extent(b), 'SpatialPolygons'))
##D q <- paste0("SELECT mukey, cokey, compname, comppct_r
##D             FROM component 
##D             WHERE mukey IN (
##D             SELECT DISTINCT mukey 
##D             FROM SDA_Get_Mukey_from_intersection_with_WktWgs84('", p, "') 
##D             )
##D             ORDER BY mukey, cokey, comppct_r DESC")
##D 
##D x <- SDA_query(q)
## End(Not run)

[Package soilDB version 1.6.3 Index]