From cf1113d107a8321f46369cb3cfbc0f854b377154 Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Tue, 13 Jun 2023 12:30:34 -0700 Subject: [PATCH 1/3] SDA_query: more error handling for error handling --- R/SDA_query.R | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/R/SDA_query.R b/R/SDA_query.R index 12deb0c7..dcf423bd 100644 --- a/R/SDA_query.R +++ b/R/SDA_query.R @@ -140,18 +140,27 @@ SDA_query <- function(q) { # error message is encapsulated in XML, use xml2 library functions to extract if (inherits(request.status, 'try-error')) { - + # get the request response, this will contain an error message - r.content <- httr::content(r, as = 'parsed', encoding = 'UTF-8') - - # parse the XML to get the error message - error.msg <- xml2::xml_text(r.content) - - ## message about bad result (previously error/warning) - message(error.msg) - + r.content <- try(httr::content(r, as = 'parsed', encoding = 'UTF-8'), silent = TRUE) + + if (!inherits(r.content, 'try-error')) { + + # parse the XML to get the error message + error.msg <- try(xml2::xml_text(r.content), silent = TRUE) + + if (inherits(error.msg, 'try-error')) { + error.msg <- "Unable to parse error message from XML response" + } + + ## message about bad result (previously error/warning) + message(error.msg) + + } + # return the error object so calling function/user can handle it return(invisible(request.status)) + } # the result is JSON: From 623ce0cf63b9e157d4b5d2eaa40185eeb7655d9a Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Thu, 27 Jul 2023 10:14:09 -0700 Subject: [PATCH 2/3] get_SDA_muaggatt: remove duplicate `mukey` column --- R/get_SDA_muaggatt.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/get_SDA_muaggatt.R b/R/get_SDA_muaggatt.R index af5c722d..e3212194 100644 --- a/R/get_SDA_muaggatt.R +++ b/R/get_SDA_muaggatt.R @@ -25,7 +25,7 @@ get_SDA_muaggatt <- function(areasymbols = NULL, mukeys = NULL, WHERE = NULL, qu WHERE <- paste("legend.areasymbol IN", format_SQL_in_statement(areasymbols)) } - q <- sprintf("SELECT mapunit.mukey, muaggatt.* + q <- sprintf("SELECT muaggatt.mukey, muaggatt.* FROM legend INNER JOIN mapunit ON mapunit.lkey = legend.lkey INNER JOIN muaggatt ON mapunit.mukey = muaggatt.mukey @@ -51,6 +51,9 @@ get_SDA_muaggatt <- function(areasymbols = NULL, mukeys = NULL, WHERE = NULL, qu warnings() stop(attr(res, 'condition')) } + + # remove duplicated mukey column + res[[ncol(res)]] <- NULL return(res) } From 6fa136473f0d8c0cb4797774e5ba0aeb16100f94 Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Thu, 27 Jul 2023 11:31:26 -0700 Subject: [PATCH 3/3] bump vignette --- vignettes/wcs-ssurgo.Rmd | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/vignettes/wcs-ssurgo.Rmd b/vignettes/wcs-ssurgo.Rmd index 4136ae17..2b15ff08 100644 --- a/vignettes/wcs-ssurgo.Rmd +++ b/vignettes/wcs-ssurgo.Rmd @@ -1,5 +1,5 @@ --- -title: "Map Unit Key Grids and Thematic Maps of SSURGO Data" +title: "Map Unit Key Grids and Thematic Maps of Soil Survey Geographic (SSURGO) Data" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Map Unit Key Grids and Thematic Maps of SSURGO Data} @@ -26,7 +26,7 @@ options(width = 100, stringsAsFactors = FALSE) ``` -This vignette will explore how to use the soilDB package to create thematic maps of SSURGO data via Soil Data Access and SoilWeb coverage services. +This vignette will explore how to use the soilDB package to create thematic maps of the Soil Survey Geographic Database (SSURGO) via Soil Data Access (SDA) and SoilWeb coverage services. # Introduction @@ -527,6 +527,7 @@ aws <- catalyze(mu2) plot( aws, axes = FALSE, + cex.main = 0.7, main = c( 'Plant Available Water Storage (cm)\nWeighted Mean over Components, 0-50cm', 'Plant Available Water Storage (cm)\nWeighted Mean over Components, 0-100cm' @@ -576,6 +577,7 @@ tab$class_ENGConstructionMaterialsRoadfill <- factor( par(mar = c(4, 12, 3, 3)) boxplot( rating_ENGConstructionMaterialsRoadfill ~ class_ENGConstructionMaterialsRoadfill, + cex.main = 0.7, main = 'ENG - Construction Materials; Roadfill', ylab = "", data = tab, @@ -603,6 +605,7 @@ rating <- catalyze(mu2) plot( rating, axes = FALSE, + cex.main = 0.7, main = c( 'Construction Materials; Roadfill\nWeighted Mean over Components', 'Irrigation Disposal of Wastewater\nWeighted Mean over Components' @@ -665,6 +668,7 @@ plot( mu, legend = FALSE, axes = FALSE, + cex.main = 0.7, main = 'gSSURGO Map Unit Key Grid' ) ``` @@ -759,13 +763,13 @@ box() Plot aggregate soil properties. ```{r} -plot(mu2[['dbthirdbar_r']], +plot(mu2[['dbthirdbar_r']], cex.main = 0.7, main = '1/3 Bar Bulk Density (g/cm^3)\nDominant Component\n0-25cm') -plot(mu2[['awc_r']], +plot(mu2[['awc_r']], cex.main = 0.7, main = 'AWC (cm/cm)\nDominant Component\n0-25cm') -plot(mu2[['ph1to1h2o_r']], +plot(mu2[['ph1to1h2o_r']], cex.main = 0.7, main = 'pH 1:1 H2O\nDominant Component\n0-25cm') ``` @@ -836,6 +840,7 @@ r <- c(ssc, texture.class) # graphical check plot( r, + cex.main = 0.7, main = paste0(names(r), " - 25-50cm\nDominant Component") ) ```