createSSURGO() updates#401
Merged
Merged
Conversation
Member
Author
|
Added library(soilDB)
library(RSQLite)
base_dir <- "D:/workspace/scratch"
.exdir1 <- file.path(base_dir, "ssurgo", "ssurgo1")
.exdir2 <- file.path(base_dir, "ssurgo", "ssurgo2")
# # download a single SSA
# downloadSSURGO(areasymbols = "ca113", destdir = .exdir1, include_template = FALSE, extract = TRUE, remove_zip = TRUE, db = "SSURGO")
#
# # download another SSA in a different directory
# downloadSSURGO(areasymbols = "ca654", destdir = .exdir2, include_template = FALSE, extract = TRUE, remove_zip = TRUE, db = "SSURGO")
# init DB file, delete if already existing
.dbfile1 <- file.path(base_dir, "ssurgo1.sqlite")
unlink(.dbfile1)
# init SQLite DB with CA113
createSSURGO(filename = .dbfile1, exdir = .exdir1, include_spatial = FALSE, overwrite = TRUE, quiet = FALSE)
#> Loading required namespace: sf
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/cfprodo.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/chtext.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/cpwndbrk.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/csmormr.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/cstemp.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/ltext.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo1/CA113/tabular/mutext.txt contains no data
# this "works" (appending three tables we just inserted) but fails uniqueness constraints so nothing happens
createSSURGO(filename = .dbfile1, exdir = .exdir1,
include_tabular = c("legend", "mapunit", "component"),
include_spatial = FALSE, append = TRUE, quiet = FALSE)
#> Error : UNIQUE constraint failed: component.cokey
#> Error : UNIQUE constraint failed: legend.lkey
#> Error : UNIQUE constraint failed: mapunit.mukey
# try to write to existing SQLite DB with CA654 [error because file exists]
createSSURGO(filename = .dbfile1, exdir = .exdir2, include_spatial = FALSE, overwrite = FALSE, quiet = FALSE)
#> Error: File 'D:/workspace/scratch/ssurgo1.duckdb' exists and overwrite=FALSE; use append=TRUE to append to an existing file
# append existing SQLite DB with CA654 [no uniqueness issues with metadata tables]
createSSURGO(filename = .dbfile1, exdir = .exdir2, include_spatial = FALSE, append = TRUE, quiet = FALSE)
#> File D:/workspace/scratch/ssurgo/ssurgo2/CA654/tabular/ccancov.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo2/CA654/tabular/cfprodo.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo2/CA654/tabular/chtext.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo2/CA654/tabular/cstemp.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo2/CA654/tabular/ltext.txt contains no data
#> File D:/workspace/scratch/ssurgo/ssurgo2/CA654/tabular/mutext.txt contains no data
soilDB::SDA_query("SELECT DISTINCT areasymbol FROM legend ;", .dbfile1)
#> areasymbol
#> 1 CA113
#> 2 CA654 |
brownag
added a commit
that referenced
this pull request
Aug 13, 2025
- geopackage case need to create gpkg_* tables via sf call, handle existing connection
brownag
added a commit
that referenced
this pull request
Aug 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
overwritelogic to close createSSURGO() does not append records when overwrite = FALSE #400; now throws an error whenfilenameexists andoverwrite=FALSEappendargument for unambiguous option to append rows to existing layers in a databaseAlso, corrects some other situations:
filenameandconnwith SQLite driver with .sqlite rather than .gpkg outputquiet=FALSE