Skip to content

Commit

Permalink
get_SDA_coecoclass: default constraint on ecoclasstypename should be …
Browse files Browse the repository at this point in the history
…`c("NRCS Rangeland Site", "NRCS Forestland Site")`
  • Loading branch information
brownag committed Jan 9, 2024
1 parent d4f2955 commit 59dbe0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# soilDB 2.8.1 (2024-01-08)
# soilDB 2.8.1 (2024-01-09)

- `get_mapunit_from_NASIS()`, `get_lmuaoverlap_from_NASIS()` and `get_legend_from_NASIS()` gain `areatypename` argument used for filtering legends by `areatypename`.
- Default results include `"Non-MLRA Soil Survey Area"` and `"MLRA Soil Survey Area"`. Set to `NULL` for no filter.
Expand All @@ -9,7 +9,10 @@
- Upgraded SoilProfileCollection spatial promotion for aqp 2.0+
- Added 10 kPa, 33 kPa and 1500 kPa water content estimates to default variable sets for point and grid queries
- `fetchSDA_spatial()` gains ability to query mapunit delineations by Ecological Site ID (`by.col="ecoclassid"`)

- `get_SDA_coecoclass()` default `ecoclasstypename` is now `c("NRCS Rangeland Site", "NRCS Forestland Site")`, as this is the most common type of aggregation and is least prone to producing unusual composition-related errors due to duplications
- Fixed bug related to merging tables/integer data type
- Fixed bug in calculation of "Not assigned" fraction of mapunits which could result in negative aggregate component percentages below the default threshold

# soilDB 2.8.0 (2023-12-22)

- Minimum {aqp} version set to v2.0.2. This is due to changes in the namespace related to `aqp::col2Munsell()`, to "encourage" users to update to the more efficient routines provided in {aqp} 2+ (if they haven't already), and prepare for future updates in the 2.x series.
Expand Down
20 changes: 10 additions & 10 deletions R/get_SDA_coecoclass.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param mukeys vector of map unit keys
#' @param WHERE character containing SQL WHERE clause specified in terms of fields in `legend`, `mapunit`, `component` or `coecosite` tables, used in lieu of `mukeys` or `areasymbols`
#' @param query_string Default: `FALSE`; if `TRUE` return a character string containing query that would be sent to SDA via `SDA_query`
#' @param ecoclasstypename If `NULL` no constraint on `ecoclasstypename` is used in the query.
#' @param ecoclasstypename Default: `c("NRCS Rangeland Site", "NRCS Forestland Site")`. If `NULL` no constraint on `ecoclasstypename` is used in the query.
#' @param ecoclassref Default: `"Ecological Site Description Database"`. If `NULL` no constraint on `ecoclassref` is used in the query.
#' @param not_rated_value Default: `"Not assigned"`
#' @param miscellaneous_areas logical. Include miscellaneous areas (non-soil components)?
Expand All @@ -21,7 +21,7 @@
get_SDA_coecoclass <- function(method = "None",
areasymbols = NULL, mukeys = NULL, WHERE = NULL,
query_string = FALSE,
ecoclasstypename = NULL,
ecoclasstypename = c("NRCS Rangeland Site", "NRCS Forestland Site"),
ecoclassref = "Ecological Site Description Database",
not_rated_value = "Not assigned",
miscellaneous_areas = TRUE,
Expand Down Expand Up @@ -148,15 +148,15 @@ get_SDA_coecoclass <- function(method = "None",

.get_SDA_coecoclass_agg <- function(areasymbols = NULL,
mukeys = NULL,
ecoclasstypename = NULL,
ecoclasstypename = c("NRCS Rangeland Site", "NRCS Forestland Site"),
ecoclassref = "Ecological Site Description Database",
not_rated_value = "Not assigned",
miscellaneous_areas = TRUE,
include_minors = TRUE,
dsn = NULL,
threshold = 0) {

comppct_r <- NULL; condpct_r <- NULL; compname <- NULL; ecoclasstypename <- NULL
comppct_r <- NULL; condpct_r <- NULL; compname <- NULL; # ecoclasstypename <- NULL
areasymbol <- NULL; compnames <- NULL; unassigned <- NULL;
mukey <- NULL; .N <- NULL; .SD <- NULL; .GRP <- NULL;

Expand Down Expand Up @@ -199,21 +199,21 @@ get_SDA_coecoclass <- function(method = "None",
res2 <- data.table::data.table(subset(res1, areasymbol != "US"))

# remove FSG etc. some components have no ES assigned, but have other eco class
idx <- !res2$ecoclassref %in% c(not_rated_value, "Not assigned", "Ecological Site Description Database") &
!res2$ecoclasstypename %in% c(not_rated_value, "Not assigned", "NRCS Rangeland Site", "NRCS Forestland Site")
idx <- !res2$ecoclassref %in% c(not_rated_value, "Not assigned", ecoclassref) &
!res2$ecoclasstypename %in% c(not_rated_value, "Not assigned", ecoclasstypename)

res2$ecoclassid[idx] <- not_rated_value
res2$ecoclassref[idx] <- not_rated_value
res2$ecoclassname[idx] <- not_rated_value
res2$ecoclasstypename[idx] <- not_rated_value

.ECOCLASSTYPENAME <- ecoclasstypename

res3 <- res2[, list(
condpct_r = sum(comppct_r, na.rm = TRUE),
compnames = paste0(compname[ecoclasstypename %in% c("NRCS Rangeland Site",
"NRCS Forestland Site")],
compnames = paste0(compname[ecoclasstypename %in% .ECOCLASSTYPENAME],
collapse = ", "),
unassigned = paste0(compname[!ecoclasstypename %in% c("NRCS Rangeland Site",
"NRCS Forestland Site")],
unassigned = paste0(compname[!ecoclasstypename %in% .ECOCLASSTYPENAME],
collapse = ", ")
), by = c("mukey", "ecoclassid", "ecoclassname")][, rbind(
.SD[, 1:4],
Expand Down
4 changes: 2 additions & 2 deletions man/get_SDA_coecoclass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59dbe0b

Please sign in to comment.