Description Usage Arguments Details Value Note Author(s) See Also Examples
Submit a query to the Soil Data Acccess (SDA) website in SQL, get the results as a dataframe.
1 |
q |
a valid T-SQL query surrounded by double quotes |
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
A dataframe containing the results. NULL is retutned when queries result in 0 matches rows.
This function requires the 'httr', 'jsonlite', and 'XML' packages
D.E. Beaudette
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # SSURGO export metadata:
## Not run:
q <- "SELECT areasymbol, saverest FROM sacatalog WHERE areasymbol LIKE 'CA%';"
x <- SDA_query(q)
x$saverest <- as.Date(x$saverest, format="%m/%d/%Y")
head(x)
## End(Not run)
# basic query:
## Not run:
res <- SDA_query("select cokey, compname, comppct_r
from component
where compname = 'yolo' and majcompflag = 'Yes' ")
## End(Not run)
# get component-level data for a specific soil survey area (Yolo county, CA)
## Not run:
q <- "SELECT
component.mukey, cokey, comppct_r, compname, taxclname,
taxorder, taxsuborder, taxgrtgroup, taxsubgrp
FROM legend
INNER JOIN mapunit ON mapunit.lkey = legend.lkey
LEFT OUTER JOIN component ON component.mukey = mapunit.mukey
WHERE legend.areasymbol = 'CA113'"
res <- SDA_query(q)
## End(Not run)
# get tabular data based on result from spatial query:
# requires raster and rgeos packages
## Not run:
library(raster) # suggested by soilDB
library(rgeos) # additional
# text -> bbox -> WKT
# xmin, xmax, ymin, ymax
b <- c(-120.9, -120.8, 37.7, 37.8)
p <- writeWKT(as(extent(b), 'SpatialPolygons'))
q <- paste0("SELECT mukey, cokey, compname, comppct_r
FROM component
WHERE mukey IN (
SELECT DISTINCT mukey
FROM SDA_Get_Mukey_from_intersection_with_WktWgs84('", p, "')
)
ORDER BY mukey, cokey, comppct_r DESC")
x <- SDA_query(q)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.