Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
docs
inst/doc
FIHS.pdf
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: hydricsoils
Type: Package
Title: Tools for 'Field Indicators of Hydric Soils in the United States'
Version: 0.1.1
Version: 0.1.2
Author: Andrew G. Brown
Maintainer: Andrew G. Brown <brown.andrewg@gmail.com>
Description: The goal of 'hydricsoils' is to provide easy access to definitions, criteria, and area of applicability for 'Field Indicators of Hydric Soils in the United States' and also to provide tools which assist in evaluating associated soil morphology.
Expand All @@ -10,7 +10,7 @@ Encoding: UTF-8
LazyData: false
Depends: R (>= 4.0.0)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
URL: https://github.com/brownag/hydricsoils/, https://humus.rocks/hydricsoils/
BugReports: https://github.com/brownag/hydricsoils/issues/
Imports:
Expand Down
Binary file removed FIHS.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
export(cache_lrrmlra_geometry)
export(clear_lrrmlra_geometry)
export(fihs_match)
export(hydricsoils_data_dir)
export(indicator_to_name)
export(indicator_to_usesym)
export(lrr_to_lrrname)
export(lrr_to_mlra)
export(lrrmlra_geometry)
export(lrrmlra_geometry_dsn)
export(lrrmlra_match)
export(lrrname_to_lrr)
export(mlra_to_lrr)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Changes in version 0.1.2

## Improvements

- Update `fihs` dataset for Field Indicators of Hydric Soils v9.0

- Adds new "All Soils" indicator: "A18" _Iron Monosulfide_

- Updated `lrrmlra` geometry source URL

## Additions

- Added `lrrmlra_geometry_dsn()` and `hydricsoils_data_dir()` functions for getting data sources and paths

# Changes in version 0.1.1

## Improvements
Expand Down
35 changes: 21 additions & 14 deletions R/cache_lrrmlra_geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
#' }
#'
cache_lrrmlra_geometry <- function(overwrite = FALSE,
dsn = "/vsizip//vsicurl/https://www.nrcs.usda.gov/sites/default/files/2022-10/MLRA_52_2022.zip/MLRA_52_2022") {
dsn = lrrmlra_geometry_dsn()) {

if (is.null(dsn)) {
dsn <- "/vsizip//vsicurl/https://www.nrcs.usda.gov/sites/default/files/2022-10/MLRA_52_2022.zip/MLRA_52_2022"
dsn <- lrrmlra_geometry_dsn()
}

fp <- file.path(tools::R_user_dir("hydricsoils", which = "data"),
"lrrmlra.gpkg")
fp <- file.path(hydricsoils_data_dir(), "lrrmlra.gpkg")

if (!requireNamespace("terra")) {
stop("package 'terra' is required to cache the LRR/MLRA spatial dataset")
stop("package 'terra' is required to create local MLRA Geographic Database cache")
}

if (!dir.exists(dirname(fp))) {
Expand All @@ -58,21 +57,29 @@ cache_lrrmlra_geometry <- function(overwrite = FALSE,
#' @rdname lrrmlra-geometry
#' @return `clear_lrrmlra_geometry()`: logical. Called for the side-effect of removing the MLRA geometry file from the cache. Returns `TRUE` if `"lrrmlra.gpkg"` is successfully removed from user data cache.
clear_lrrmlra_geometry <- function() {
invisible(file.remove(file.path(
tools::R_user_dir("hydricsoils", which = "data"),
"lrrmlra.gpkg"
)))
invisible(
file.remove(
file.path(hydricsoils_data_dir(), "lrrmlra.gpkg")
)
)
}

#' @export
#' @rdname lrrmlra-geometry
#' @return `lrrmlra_geometry()`: A terra _SpatVector_ object containing `lrrmlra` attributes and geometry.
lrrmlra_geometry <- function(overwrite = FALSE,
dsn = "/vsizip//vsicurl/https://www.nrcs.usda.gov/sites/default/files/2022-10/MLRA_52_2022.zip/MLRA_52_2022") {
dsn = lrrmlra_geometry_dsn()) {
if (cache_lrrmlra_geometry(overwrite = overwrite, dsn = dsn)) {
return(terra::vect(file.path(
tools::R_user_dir("hydricsoils", which = "data"),
"lrrmlra.gpkg"
)))
return(terra::vect(
file.path(hydricsoils_data_dir(), "lrrmlra.gpkg")
))
}
}

#' @export
#' @rdname lrrmlra-geometry
#' @return `lrrmlra_geometry_dsn()`: character. Path to MLRA Geographic Database source.
lrrmlra_geometry_dsn <- function() {
# "https://www.nrcs.usda.gov/sites/default/files/2022-10/MLRA_52_2022.zip/MLRA_52_2022"
"/vsizip//vsicurl/https://s3-fpac-nrcs-dshub-public.s3.us-gov-west-1.amazonaws.com/MLRA_52_2022.zip"
}
1 change: 1 addition & 0 deletions R/hydricsoils-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
## usethis namespace: start
## usethis namespace: end
NULL

12 changes: 12 additions & 0 deletions R/hydricsoils.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@
#' @keywords datasets
#' @references United States Department of Agriculture, Natural Resources Conservation Service. 2022. Land resource regions and major land resource areas of the United States, the Caribbean, and the Pacific Basin. U.S. Department of Agriculture, Agriculture Handbook 296. Available online: <https://www.nrcs.usda.gov/resources/data-and-reports/major-land-resource-area-mlra>
"lrrmlra"

#' hydricsoils Data Directory
#' @returns `hydricsoils_data_dir()`: character. Path to hydricsoil package user
#' data directory. Default: `tools::R_user_dir("hydricsoils", which = "data")`
#' @export
#' @examples
#'
#' hydricsoils_data_dir()
#'
hydricsoils_data_dir <- function() {
tools::R_user_dir("hydricsoils", which = "data")
}
31 changes: 21 additions & 10 deletions data-raw/fihs.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
## code to prepare `fihs` dataset goes here
# download.file("https://www.nrcs.usda.gov/sites/default/files/2022-09/Field_Indicators_of_Hydric_Soils.pdf",
# download.file("https://www.nrcs.usda.gov/sites/default/files/2024-09/Field-Indicators-of-Hydric-Soils.pdf",
# destfile = "FIHS.pdf", mode = "wb")
# system("pdftotext -raw -nodiag FIHS.pdf FIHS.txt")

# # remove figure captions manually
x <- readLines("inst/extdata/FIHS.txt", warn = FALSE)
f <- readLines("inst/extdata/FIGS.txt", warn = FALSE)

# clean FIGS
cat(trimws(strsplit(paste0(f, collapse = " "), "—")[[1]]), file = "inst/extdata/FIGS.txt", sep = "\n")

f <- readLines("inst/extdata/FIGS.txt", warn = FALSE)


## metadata, added as attributes
VERSION <- "8.2"
VERSION_YEAR <- "2018"
REFERENCE <- "United States Department of Agriculture, Natural Resources Conservation Service. 2018. Field Indicators of Hydric Soils in the United States, Version 8.2. L.M. Vasilas, G.W. Hurt, and J.F. Berkowitz (eds.). USDA, NRCS, in cooperation with the National Technical Committee for Hydric Soils. Available online: <https://www.nrcs.usda.gov/resources/guides-and-instructions/field-indicators-of-hydric-soils>"
VERSION <- "9.0"
VERSION_YEAR <- "2024"
REFERENCE <- "United States Department of Agriculture, Natural Resources Conservation Service. 2024. Field Indicators of Hydric Soils in the United States, Version 9.0. Available online: <https://www.nrcs.usda.gov/resources/guides-and-instructions/field-indicators-of-hydric-soils>"

#
##
Expand All @@ -22,7 +28,8 @@ REFERENCE <- "United States Department of Agriculture, Natural Resources Conserv
##
## somehow rebuild suitable text vector from `fd` ...
##
idx <- grep("^All Soils$|^Sandy Soils$|^Loamy and Clayey Soils$|Test Indicators of Hydric Soils$|^\\f\\fAccessibility Statement$", x)
idx <- grep("^Introduction$|^All Soils$|^Sandy Soils$|^Loamy and Clayey Soils$|Test Indicators of Hydric Soils$|^References$", x)
idx <- idx[4:8]
x <- gsub("(for use in all LRRs) or Histel (for", "or Histel. ", x, fixed = TRUE)
x <- gsub("use in LRRs with permafrost). ", "", x, fixed = TRUE)
x <- gsub("from12 to18 percent", "from 12 to 18 percent", x)
Expand All @@ -34,16 +41,18 @@ x[grep("A1.\u2014", x) + 1]
sec.idx <- c(idx - 1, length(x))
sec.len <- diff(c(0, sec.idx))
sec.lbl <- c("Field Indicators of Hydric Soils",
"Front Matter",
"All Soils", "Sandy Soils", "Loamy and Clayey Soils",
"Test Indicators", "All Soils (Test)", "Sandy Soils (Test)",
"Loamy and Clayey Soils (Test)", "End Matter")
# "Test Indicators",
# "All Soils (Test)", "Sandy Soils (Test)", "Loamy and Clayey Soils (Test)",
"End Matter")
page.idx <- grep("^\\f+", x)
page.len <- diff(c(0, page.idx))
page.num <- gsub("^\\f+([0-9iv]+).*(Hydric Soils|Field Indicators of)?", "\\1", x[page.idx])
page.idx <- page.idx - 1
page.num[1] <- "i"
page.num[49] <- page.num[48]
page.num[48] <- "46"
page.num[40] <- "36"
page.num[55] <- "52"
page.num <- gsub("\\f", "", page.num)

# break out page numbers and sections for each line of content
Expand Down Expand Up @@ -219,10 +228,12 @@ fihs <- fihs[c("section", "indicator", "indicator_name", "page",

if (interactive())
View(fihs)

fihs <- fihs[-1,]
rownames(fihs) <- NULL
attr(fihs, 'version') <- VERSION
attr(fihs, 'version_year') <- VERSION_YEAR
attr(fihs, 'reference') <- REFERENCE
fihs90 <- fihs
usethis::use_data(fihs, overwrite = TRUE)

## TODO: fihs_test dataset; need to confirm where they are being tested
Expand Down
Loading