1 Introduction

This is a short tutorial on how to interact with the Soil Data Access (SDA) web-service using R. Queries are written using a dialect of SQL. On first glance SQL appears similar to the language used to write NASIS queries and reports, however, these are two distinct languages. Soil Data Access is a “window” into the spatial and tabular data associated with the current SSURGO snapshot. Queries can contain spatial and tabular filters. If you are new to SDA or SQL, have a look at this page. Here is a SSURGO-specific library of SQL code, organized by task.

Spatial queries can be included in SQL statements submitted to SDA as long as the geometry has first been transformed to WGS84 geographic (or psuedo-Web Mercator) coordinates and formatted as “well known text” (WKT). The sp and rgdal packages provide functionality for converting between coordinate systems via spTransform(). Coordinate reference system definitions (a “CRS”) are typically provided using proj4 notation. You can search for various CRS definitions in a variety of formats using spatialreference.org/.

The soilDB library for R provides a helper function (SDA_query()) for submitting queries to SDA, processing the result, and reformatting the results into a rectangular table (a data.frame). Most of the work required to use the SDA_query() function will be writing SQL to describe the columns you would like returned and how the data should be filtered and possibly grouped.

Follow along with the blocks of code below by copying / pasting into a new R “script” document. Each block of command can be run by pasting into the R console, or by “stepping through” lines of code by