The following database types are tested and fully supported:
SQLite or Geopackage
DuckDB
Postgres or PostGIS
Usage
createSSURGO(
filename = NULL,
exdir = NULL,
conn = NULL,
pattern = NULL,
include_spatial = TRUE,
include_tabular = TRUE,
include_raster = FALSE,
LAPPLY.FUN = lapply,
LAPPLY.FUN.ARGS = NULL,
dissolve_field = NULL,
maxruledepth = 0,
overwrite = FALSE,
append = FALSE,
header = FALSE,
sep = "|",
na.strings = c("", "NA"),
quote = "",
fiscal_year = NULL,
template = NULL,
touches = FALSE,
grid_alignment = c("gssurgo", "target_aligned", "nlcd"),
resolution_m = 10,
quiet = TRUE,
areasymbols = NULL,
...
)Arguments
- filename
character. Output file name (e.g.
'db.sqlite'or'db.gpkg'). Only used whenconis not specified by the user.- exdir
character. Path containing input SSURGO spatial (.shp) and tabular (.txt) files, downloaded and extracted by
downloadSSURGO()or similar. Default:NULLselects the most recent fiscal-year cache directory.- conn
A DBIConnection object. Default is a
SQLiteConnectionused for writing .sqlite or .gpkg files. Alternate options are any DBI connection types. Wheninclude_spatial=TRUE, the sf package is used to write spatial data to the database.- pattern
character. Optional regular expression to use to filter subdirectories of
exdir. Default:NULLwill search all subdirectories for SSURGO export files.- include_spatial
logical or character. Include spatial data layers in database? Default:
TRUEinserts all spatial tables. Ifinclude_spatialis a character vector containing table names, only that set are written to file. e.g.include_spatial=c("mupolygon", "featpoint")writes only the mapunit polygons and special feature points.- include_tabular
logical or character. Include tabular data layers in database? Default:
TRUEinserts all tabular tables. Ifinclude_tabularis a character vector containing table names, only that set are written to file. e.g.include_tabular=c("mapunit", "muaggatt")writes only themapunitandmuaggatttables. Note that special feature descriptions are stored in table"featdesc"and metadata for each soil survey area are stored in"soil_metadata"tables.- include_raster
logical. Generate MUKEY GeoTIFF rasters for each SSA? Default:
FALSEdoes not create raster outputs. Set toTRUEto create georeferenced rasters cached insoilDB_user_dir("cache", "WSS", ...)and output a combined/copied raster matchingfilename. Requiresterrapackage.- LAPPLY.FUN
function.
lapply()-like function to use for iteration during rasterization phase. Only used ifinclude_raster=TRUE. This allows for the rasterization operations to be run in parallel instead of sequential, custom progress reporting, or similar.- LAPPLY.FUN.ARGS
list. Optional list of additional arguments to pass to
LAPPLY.FUN.- dissolve_field
character. Dissolve geometries to create MULTIPOLYGON features? Column name specified is the grouping variable. Default:
NULLdoes no aggregation, giving 1POLYGONfeature per delineation."mukey"aggregates all related delineations within a soil survey area.- maxruledepth
integer. Maximum rule depth for
"cointerp"table. Default0includes only shallowest ratings for smaller database size.- overwrite
logical. Overwrite existing layers? Default:
FALSE- append
logical. Append to existing layers? Default:
FALSE- header
logical. Passed to
data.table::fread()for reading delimited tabular text files. Default:FALSE- sep
character. Passed to
data.table::fread(). Default:"|"- na.strings
character. Passed to
data.table::fread(). Default:c("", "NA")- quote
character. Passed to
data.table::fread(). Default:""- fiscal_year
character. Optional fiscal year label for cache organization (e.g.,
'FY2024','FY26'). IfNULL, auto-detect from sacatalog saverest date. Allows organizing rasters by official release year or custom labels. Only used ifinclude_raster=TRUE.- template
Optional
SpatRastertemplate defining a common target CRS and grid, including cell size, for all selected SSAs. Use a template when the selection spans regional CRSs or when a geographic CRS is needed. IfNULL(default), creates a standard grid atresolution_min the regional standard CRS (EPSG:5070 for CONUS, EPSG:3338 for AK, EPSG:6628 for HI, EPSG:32161 for PR/VI, EPSG:4326 for Pacific Islands) with bounds snapped according togrid_alignment.- touches
logical. If
TRUE, all cells touched by polygon boundaries are rasterized. DefaultFALSErasterizes only cells whose centroids fall within polygons.- grid_alignment
character. Grid alignment mode when
template = NULL. Use"gssurgo"(default),"target_aligned", or"nlcd". The GSSURGO mode uses a half-cell origin matching official USDA-NRCS products; target-aligned uses a zero origin; and NLCD uses the canonical WGS84 Albers origin anchor(-2415585, 3314805). A suppliedtemplatetakes precedence.- resolution_m
numeric. Finite positive raster cell size in meters when
template = NULLand the regional CRS is projected (default:10). Meter-based rasterization with a geographic regional CRS requires an explicittemplate.- quiet
logical. Suppress messages and other output from database read/write operations?
- areasymbols
character. Optional character vector of soil survey area symbols (e.g.
c("CA067", "CA077")) used to subset the folders/files withinexdirto process. DefaultNULLprocesses all SSURGO exports found inexdir.- ...
Additional arguments passed to
sf::write_sf()for writing spatial layers.
Details
In theory any other DBI-compatible data source can be used for output. See conn argument. If
you encounter issues using specific DBI connection types, please report in the soilDB issue
tracker.
When include_raster=TRUE, common resolutions include 10m, 30m, 300m, and 900m; any positive
resolution can be requested. Custom SpatRaster templates can be supplied for arbitrary grids.
The alignment modes are
intentional: gssurgo matches official USDA-NRCS products, target_aligned follows
zero-origin GDAL-style alignment, and nlcd uses the canonical WGS84 Albers origin. These
choices support interoperability with federal raster products including NLCD, CDL, USGS 3DEP,
and gNATSGO. A supplied template defines a common CRS and grid for all selected SSAs. Without
a template, selected SSAs must share a regional CRS. The Pacific Island default CRS (EPSG:4326)
is geographic, so meter-based rasterization there requires an explicit template. Raster output
uses NAflag = 0; MUKEY zero is reserved as NoData.
A single SSURGO MUKEY per cell may be misleading at resolutions greater than 90 meters. A warning is issued for recognized SSURGO area symbols when the output grid exceeds this resolution.
Examples
if (FALSE) { # \dontrun{
downloadSSURGO("areasymbol IN ('CA067', 'CA077', 'CA632')", destdir = "SSURGO_test")
createSSURGO("test.gpkg", "SSURGO_test")
} # }