SDA_query: Soil Data Access Query

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

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

Usage

1

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

 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)

soilDB documentation built on May 2, 2019, 5:17 p.m.