| Title: | Download and Interact with the 'SSURGO Portal' Tools for Building and Editing U.S. Soil Survey Databases |
|---|---|
| Description: | Provides methods for downloading and interacting with the 'SSURGO Portal' Python tools. |
| Authors: | Soil Survey Staff |
| Maintainer: | Andrew Brown <[email protected]> |
| License: | CC0 |
| Version: | 0.0.6 |
| Built: | 2026-05-17 08:05:07 UTC |
| Source: | https://github.com/brownag/SSURGOPortalR |
Uses 'reticulate' to create a virtual environment with the SSURGO Portal
dependencies. Select the environment name, default "r-ssurgoportal",
along with the specific Python and GDAL versions.
create_ssurgo_venv( envname = "r-ssurgoportal", python_version = SSURGOPORTAL_PYTHON_VERSION(), gdal_version = SSURGOPORTAL_GDAL_VERSION(), conda = FALSE, install_python = TRUE, ... ) ssurgo_portal_python( envname = getOption("SSURGOPortal.virtualenv_name", default = "r-ssurgoportal"), conda = FALSE, ... )create_ssurgo_venv( envname = "r-ssurgoportal", python_version = SSURGOPORTAL_PYTHON_VERSION(), gdal_version = SSURGOPORTAL_GDAL_VERSION(), conda = FALSE, install_python = TRUE, ... ) ssurgo_portal_python( envname = getOption("SSURGOPortal.virtualenv_name", default = "r-ssurgoportal"), conda = FALSE, ... )
envname |
character. Python virtual environment name. Default: |
python_version |
character. Semantic version number of 'Python' to install if not available. Default: '"3.10.2" |
gdal_version |
character. Semantic version number of 'GDAL' package to install. Default: |
conda |
logical. Look for Conda environment instead of virtual environment? Default: |
install_python |
logical. Install Python from official source using |
... |
Additional arguments used only when |
character. Path to virtual environment Python binary (invisible).
Download ZIP files containing spatial (ESRI shapefile) and tabular (TXT) files with standard SSURGO format; optionally including the corresponding SSURGO Template Database with include_template=TRUE.
download_ssurgo( WHERE = NULL, areasymbols = NULL, destdir = tempdir(), exdir = destdir, include_template = FALSE, extract = TRUE, remove_zip = FALSE, overwrite = FALSE, quiet = FALSE )download_ssurgo( WHERE = NULL, areasymbols = NULL, destdir = tempdir(), exdir = destdir, include_template = FALSE, extract = TRUE, remove_zip = FALSE, overwrite = FALSE, quiet = FALSE )
WHERE |
A SQL |
areasymbols |
Character vector of soil survey area symbols e.g. |
destdir |
Directory to download ZIP files into. Default |
exdir |
Directory to extract ZIP archives into. May be a directory that does not yet exist. Each ZIP file will extract to a folder labeled with |
include_template |
Include the (possibly state-specific) MS Access template database? Default: |
extract |
Logical. Extract ZIP files to |
remove_zip |
Logical. Remove ZIP files after extracting? Default: |
overwrite |
Logical. Overwrite by re-extracting if directory already exists? Default: |
quiet |
Logical. Passed to |
To specify the Soil Survey Areas you would like to obtain data you use a WHERE clause for query of sacatalog table such as areasymbol = 'CA067', "areasymbol IN ('CA628', 'CA067')" or areasymbol LIKE 'CT%'.
Pipe-delimited TXT files are found in /tabular/ folder extracted from a SSURGO ZIP. The files are named for tables in the SSURGO schema. There is no header / the files do not have column names. See the Soil Data Access Tables and Columns Report: https://sdmdataaccess.nrcs.usda.gov/documents/TablesAndColumnsReport.pdf for details on tables, column names and metadata including the default sequence of columns used in TXT files. The function returns a try-error if the WHERE/areasymbols arguments result in
Several ESRI shapefiles are found in the /spatial/ folder extracted from a SSURGO ZIP. These have prefix soilmu_ (mapunit), soilsa_ (survey area), soilsf_ (special features). There will also be a TXT file with prefix soilsf_ describing any special features. Shapefile names then have an a_ (polygon), l_ (line), p_ (point) followed by the soil survey area symbol.
Character. Paths to downloaded ZIP files (invisibly). May not exist if remove_zip=TRUE.
This routine downloads the latest .pyz file from Web Soil Survey
install_ssurgo_portal( verbose = TRUE, overwrite = FALSE, timeout = 3000, src = "https://websoilsurvey.sc.egov.usda.gov/DSD/Download/SsurgoPortal/SSURGO_Portal.zip", envname = "r-ssurgoportal", python_version = SSURGOPORTAL_PYTHON_VERSION(), gdal_version = SSURGOPORTAL_GDAL_VERSION(), ... )install_ssurgo_portal( verbose = TRUE, overwrite = FALSE, timeout = 3000, src = "https://websoilsurvey.sc.egov.usda.gov/DSD/Download/SsurgoPortal/SSURGO_Portal.zip", envname = "r-ssurgoportal", python_version = SSURGOPORTAL_PYTHON_VERSION(), gdal_version = SSURGOPORTAL_GDAL_VERSION(), ... )
verbose |
Show download progress and location of file on successful download? Default |
overwrite |
Overwrite existing .PYZ file? Default: |
timeout |
Default: |
src |
Default: |
envname |
Virtual environment to create for installation. Default: |
python_version |
character. Semantic version number of 'Python' to install if not available. Default: |
gdal_version |
character. Semantic version number of 'GDAL' package to install. Default: |
... |
Additional arguments to |
Path to downloaded file, or try-error on error.
## Not run: install_ssurgo_portal() ## End(Not run)## Not run: install_ssurgo_portal() ## End(Not run)
Generate commands for the 'SSURGO Portal' Data Loader command-line interface, and parse resulting JSON output.
ssurgo_portal( request = NULL, pyz_path = file.path(ssurgo_portal_dir("data"), "SSURGOPortal.pyz"), ..., schema = FALSE, command_only = FALSE )ssurgo_portal( request = NULL, pyz_path = file.path(ssurgo_portal_dir("data"), "SSURGOPortal.pyz"), ..., schema = FALSE, command_only = FALSE )
request |
One of the available request types, see Details. |
pyz_path |
Path to "SSURGO Portal" .pyz file. Default |
... |
Additional parameters for |
schema |
Return request and response schemas? Default: |
command_only |
Return command string rather than executing it? Default: |
| Request Name | Description |
| getstatus | Quick check for application responsiveness |
| getusage | Return usage information in payload. |
| getwindowsdriveletters | Return all drive letters (only valid for Microsoft Windows) |
| getfoldertree | Returns a file system tree. |
| gettemplatecatalog | Returns JSON containing information about all available empty SSURGO SQLite templates. |
| copytemplatefile | Copies a template file to a specified folder path and name. |
| opentemplate | Opens a SQLite file to confirm that it meets certain minimal criteria. |
| getdatabaseinventory | List survey areas and related data within a SQLite database. |
| deleteareasymbols | Delete the specified areasymbols from the database. |
| pretestimportcandidates | Perform a 'pre-test' on subfolders under a root folder. |
| importcandidates | Import SSURGO data from subfolders under a root folder. The import terminates if any folder fails. |
| importspatialdata | For internal use only. Import SSURGO spatial data from shapefiles under a specified path. Note that this activity is isolated to support its use in a child process. |
| getrecordlistbytable | Retrieve table rows for a specified table |
| generaterasters | Generate rasters of the mupolygon dataset in the user specified SSURGO Template Database. |
| logjavascripterror | Write an error to the log file |
| getsdvattributesbyfolder | Get Soil Data Viewer attributes |
| getsdvratingoptions | Get Soil Data Viewer rating options |
| generateaggregation | Generate an aggregation |
| sortratingtable | Sort a rating table by a specified column name |
| exportratingresults | Export rating results |
A list object corresponding to the JSON response. NULL (invisibly) on error along with any other standard output from the tool printed to the console.
## Not run: ssurgo_portal("getstatus") ssurgo_portal("getstatus", schema = TRUE) ssurgo_portal( "getfoldertree", path = "C:/SSURGO Portal/WV", folderpattern = "WV", filepattern = "txt", ignorefoldercase = TRUE, ignorefilecase = TRUE, showfiles = FALSE, maxdepth = 2 ) ssurgo_portal("gettemplatecatalog") ssurgo_portal( "copytemplate", templatename = "GeoPackage", folder = "test", filename = "test.gpkg", overwrite = TRUE ) dbp <- "C:/SSURGO Portal/Databases/West_Virginia_Geopackage.gpkg" ssurgo_portal("opentemplate", database = dbp) ssurgo_portal( "pretestimportcandidates", database = dbp, root = "C:/SSURGO Portal/WV", istabularonly = FALSE ) ssurgo_portal( "importcandidates", database = dbp, root = "C:/SSURGO Portal/WV", istabularonly = FALSE, skippretest = TRUE, subfolders = list("WV603"), loadinspatialorder = FALSE, loadspatialdatawithinsubprocess = TRUE, dissolvemupolygon = TRUE ) ssurgo_portal("getdatabaseinventory", database = dbp) ssurgo_portal("deleteareasymbols", database = dbp, areasymbols = list("WV603")) ## End(Not run)## Not run: ssurgo_portal("getstatus") ssurgo_portal("getstatus", schema = TRUE) ssurgo_portal( "getfoldertree", path = "C:/SSURGO Portal/WV", folderpattern = "WV", filepattern = "txt", ignorefoldercase = TRUE, ignorefilecase = TRUE, showfiles = FALSE, maxdepth = 2 ) ssurgo_portal("gettemplatecatalog") ssurgo_portal( "copytemplate", templatename = "GeoPackage", folder = "test", filename = "test.gpkg", overwrite = TRUE ) dbp <- "C:/SSURGO Portal/Databases/West_Virginia_Geopackage.gpkg" ssurgo_portal("opentemplate", database = dbp) ssurgo_portal( "pretestimportcandidates", database = dbp, root = "C:/SSURGO Portal/WV", istabularonly = FALSE ) ssurgo_portal( "importcandidates", database = dbp, root = "C:/SSURGO Portal/WV", istabularonly = FALSE, skippretest = TRUE, subfolders = list("WV603"), loadinspatialorder = FALSE, loadspatialdatawithinsubprocess = TRUE, dissolvemupolygon = TRUE ) ssurgo_portal("getdatabaseinventory", database = dbp) ssurgo_portal("deleteareasymbols", database = dbp, areasymbols = list("WV603")) ## End(Not run)
These are standard locations for storing data, config, and cache information for SSURGO Portal outside of the installation in the R package library.
ssurgo_portal_dir(which = "data")ssurgo_portal_dir(which = "data")
which |
One or more of: |
character. Path to data, config or cache directories, respectively.
ssurgo_portal_dir("data") ssurgo_portal_dir("config") ssurgo_portal_dir("cache")ssurgo_portal_dir("data") ssurgo_portal_dir("config") ssurgo_portal_dir("cache")
SSURGOPORTAL_PYTHON_VERSION(): returns value of system environment
variable R_SSURGOPORTAL_PYTHON_VERSION or option SSURGOPortal.python_version.
If neither are set then returns "3.10", the suggested Python version.
SSURGOPORTAL_PYTHON_VERSION() SSURGOPORTAL_GDAL_VERSION()SSURGOPORTAL_PYTHON_VERSION() SSURGOPORTAL_GDAL_VERSION()
character. Version number for Python or GDAL to be used when building Python environment.