From 95e4113bdc51e5ae39d0e77400e9f8c152e46f91 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Mon, 15 Jun 2026 08:08:32 -0500 Subject: [PATCH 01/11] rerun docs --- R/read_waterdata_ratings.R | 2 ++ man/read_waterdata_continuous.Rd | 2 +- man/read_waterdata_daily.Rd | 2 +- man/read_waterdata_field_measurements.Rd | 2 +- man/read_waterdata_peaks.Rd | 2 +- tests/testthat/tests_general.R | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/read_waterdata_ratings.R b/R/read_waterdata_ratings.R index 3663592af..3bbc7a9ee 100644 --- a/R/read_waterdata_ratings.R +++ b/R/read_waterdata_ratings.R @@ -147,6 +147,8 @@ read_waterdata_ratings <- function( httr2::req_url_query(limit = limit) |> basic_request() + message("Requesting:\n", request$url) + resp <- httr2::req_perform(request) log_rate_limit(resp) diff --git a/man/read_waterdata_continuous.Rd b/man/read_waterdata_continuous.Rd index b35db8666..e722a5ede 100644 --- a/man/read_waterdata_continuous.Rd +++ b/man/read_waterdata_continuous.Rd @@ -34,7 +34,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, continuous_id, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. +geometry, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint. diff --git a/man/read_waterdata_daily.Rd b/man/read_waterdata_daily.Rd index ef3d7eede..9c0efdd08 100644 --- a/man/read_waterdata_daily.Rd +++ b/man/read_waterdata_daily.Rd @@ -41,7 +41,7 @@ Multiple statistic_ids can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, daily_id, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. +geometry, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint. diff --git a/man/read_waterdata_field_measurements.Rd b/man/read_waterdata_field_measurements.Rd index b9543526c..95271b34f 100644 --- a/man/read_waterdata_field_measurements.Rd +++ b/man/read_waterdata_field_measurements.Rd @@ -45,7 +45,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, field_measurement_id, field_measurements_series_id, field_visit_id, parameter_code, monitoring_location_id, observing_procedure_code, observing_procedure, value, unit_of_measure, time, qualifier, vertical_datum, approval_status, measuring_agency, last_modified, control_condition, measurement_rated. +geometry, field_measurements_series_id, reading_type, field_visit_id, parameter_code, monitoring_location_id, observing_procedure_code, observing_procedure, value, unit_of_measure, time, qualifier, vertical_datum, approval_status, measuring_agency, last_modified, control_condition, measurement_rated, year, month, day, time_of_day. The default (\code{NA}) will return all columns of the data.} \item{field_visit_id}{A universally unique identifier (UUID) for the field visit. Multiple measurements may be made during a single field visit.} diff --git a/man/read_waterdata_peaks.Rd b/man/read_waterdata_peaks.Rd index 79e98b2c2..6cdae7958 100644 --- a/man/read_waterdata_peaks.Rd +++ b/man/read_waterdata_peaks.Rd @@ -41,7 +41,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, time_series_id, monitoring_location_id, parameter_code, peak_id, unit_of_measure, value, last_modified, time, water_year, year, month, day, time_of_day, peak_since. +geometry, time_series_id, monitoring_location_id, parameter_code, peak_id, unit_of_measure, value, last_modified, time, water_year, year, month, day, time_of_day, peak_since, qualifier. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint.} diff --git a/tests/testthat/tests_general.R b/tests/testthat/tests_general.R index 25d272e57..ea8a2e03a 100644 --- a/tests/testthat/tests_general.R +++ b/tests/testthat/tests_general.R @@ -164,7 +164,7 @@ test_that("General NWIS retrievals working", { expect_equal(names(rating_curve), "USGS-01594440.base.rdb") state_rating_list <- read_waterdata_ratings( - datetime = c(Sys.Date() - 1, NA), + datetime = c(Sys.Date() - 1, as.Date(NA)), download_and_parse = FALSE ) From 7bbf399d49e8806f28bb942275558483b69640bf Mon Sep 17 00:00:00 2001 From: Matthew Conlon Date: Tue, 16 Jun 2026 16:43:53 -0400 Subject: [PATCH 02/11] add metadata output to read_waterdata_ratings output --- R/read_waterdata_ratings.R | 150 ++++++++++++++++++++++- tests/testthat/tests_userFriendly_fxns.R | 7 +- 2 files changed, 150 insertions(+), 7 deletions(-) diff --git a/R/read_waterdata_ratings.R b/R/read_waterdata_ratings.R index 3663592af..2c4c7269c 100644 --- a/R/read_waterdata_ratings.R +++ b/R/read_waterdata_ratings.R @@ -38,7 +38,13 @@ #' @export #' @inherit read_waterdata_continuous details #' -#' @return List of data frames which contain the requested rating curves. +#' @return List of named lists, one per requested rating file. Each element +#' contains: +#' \describe{ +#' \item{ratings}{Data frame of the rating curve.} +#' \item{metadata}{Data frame of header/value pairs parsed from the comment +#' attribute of the ratings file.} +#' } #' #' @examplesIf is_dataRetrieval_user() #' @@ -49,15 +55,15 @@ #' monitoring_location_id = monitoring_location_id, #' file_type = "exsa") #' -#' head(ratings_exsa[["USGS-01104475.exsa.rdb"]]) -#' comment(ratings_exsa[["USGS-01104475.exsa.rdb"]])[1:15] +#' head(ratings_exsa[["USGS-01104475.exsa.rdb"]]$ratings) +#' ratings_exsa[["USGS-01104475.exsa.rdb"]]$metadata #' #' ratings_corr <- read_waterdata_ratings( #' monitoring_location_id = monitoring_location_id, #' file_type = "corr") #' -#' head(ratings_corr[["USGS-01104460.corr.rdb"]]) -#' comment(ratings_corr[["USGS-01104460.corr.rdb"]])[1:15] +#' head(ratings_corr[["USGS-01104460.corr.rdb"]]$ratings) +#' ratings_corr[["USGS-01104460.corr.rdb"]]$metadata #' #' rating_2 <- read_waterdata_ratings( #' monitoring_location_id = monitoring_location_id, @@ -168,6 +174,7 @@ read_waterdata_ratings <- function( } } +# Download and convert a rating curve feature to a tidy list download_convert <- function(feature, file_path, file_type) { links <- feature$links id <- feature$id @@ -181,8 +188,139 @@ download_convert <- function(feature, file_path, file_type) { message("Requesting: \n", url) resp <- httr2::req_perform(req, path = full_file_path) rating <- importRDB1(full_file_path) - return(rating) + return(list( + ratings = rating, + metadata = parse_ratings_metadata(rating) + )) } return(NULL) } + +# Parse rating comment metadata into a data frame +parse_ratings_metadata <- function(ratings_df) { + raw_comments <- comment(ratings_df) + + if (is.null(raw_comments)) { + return(data.frame( + header = character(), + value = character(), + stringsAsFactors = FALSE + )) + } + + com <- data.frame( + line = raw_comments, + stringsAsFactors = FALSE + ) + + # remove whitespace + com$line <- sub("^#\\s*//?", "", com$line) + com$line <- sub("^//", "", com$line) + com$line <- gsub("\\s+", " ", trimws(com$line)) + + # concatenate warning info + warn_rows <- grepl("^WARNING", com$line) + warn_text <- sub("^WARNING\\s*", "", com$line[warn_rows]) + warn_text <- gsub("\\s+", " ", trimws(warn_text)) + warn_text <- warn_text[warn_text != ""] + + warning_block <- if (length(warn_text) > 0) { + paste(warn_text, collapse = " ") + } else { + "" + } + + non_warn <- com[!warn_rows, , drop = FALSE] + + # group the key-value pairs in the data + kv_pat <- '[A-Za-z0-9_]+\\s*=\\s*"[^"]*"|[A-Za-z0-9_]+\\s*=\\s*[^\\s]+' + kv_match <- regmatches( + non_warn$line, + gregexpr(kv_pat, non_warn$line, perl = TRUE) + ) + has_kv <- sapply(kv_match, length) > 0 + kv_flat <- unlist(kv_match, use.names = FALSE) + + pairs_df <- data.frame( + header = sub("^([A-Za-z0-9_]+).*", "\\1", kv_flat, perl = TRUE), + value = gsub( + '^"|"$', + "", + gsub( + "\\s+", + " ", + trimws( + sub("^[A-Za-z0-9_]+\\s*=\\s*", "", kv_flat, perl = TRUE) + ) + ) + ), + stringsAsFactors = FALSE + ) + + # handle data with colons + colon_pat <- "^[A-Z][A-Z _-]+:" + colon_rows <- grepl(colon_pat, non_warn$line) + colon_lines <- non_warn$line[colon_rows] + + date_df <- data.frame( + header = gsub( + "\\s+", + " ", + trimws( + sub("^([A-Z][A-Z _-]+):.*$", "\\1", colon_lines, perl = TRUE) + ) + ), + value = gsub( + "\\s+", + " ", + trimws( + sub("^[A-Z][A-Z _-]+:\\s*", "", colon_lines, perl = TRUE) + ) + ), + stringsAsFactors = FALSE + ) + + # parse any lines that don't fit other patterns + other_lines <- non_warn$line[!has_kv & !colon_rows] + + other_df <- data.frame( + header = gsub( + "\\s+", + " ", + trimws( + sub("^([A-Z][A-Z _-]+).*$", "\\1", other_lines, perl = TRUE) + ) + ), + value = gsub( + "\\s+", + " ", + trimws( + sub("^[A-Z][A-Z _-]+\\s*", "", other_lines, perl = TRUE) + ) + ), + stringsAsFactors = FALSE + ) + + # combine into one dataframe to be added to list object + final <- rbind( + data.frame( + header = "WARNING", + value = warning_block, + stringsAsFactors = FALSE + ), + pairs_df, + date_df, + other_df + ) + + final$value <- gsub("[\\x00-\\x1F\\x7F]+", " ", final$value, perl = TRUE) + final$value <- gsub("\\s+", " ", trimws(final$value)) + final$header <- gsub("\\s+", " ", trimws(final$header)) + + final <- final[!(final$header == "" & final$value == ""), , drop = FALSE] + final <- unique(final) + rownames(final) <- NULL + + final +} diff --git a/tests/testthat/tests_userFriendly_fxns.R b/tests/testthat/tests_userFriendly_fxns.R index 393c13b4b..c41abfae6 100644 --- a/tests/testthat/tests_userFriendly_fxns.R +++ b/tests/testthat/tests_userFriendly_fxns.R @@ -123,7 +123,12 @@ test_that("peak, rating curves, surface-water measurements", { monitoring_location_id = siteNumber, file_type = "base" ) - expect_gt(length(comment(data[[1]])), 1) + expect_type(data, "list") + expect_length(data, 1) + + sub <- data[[1]] + expect_type(sub, "list") + expect_setequal(names(sub), c("ratings", "metadata")) # Surface meas: siteNumbers <- c("USGS-01594440", "USGS-040851325") From d818d772b94e6dd287f1529c9d6232a9c2bcdd56 Mon Sep 17 00:00:00 2001 From: Matthew Conlon Date: Thu, 18 Jun 2026 10:44:56 -0400 Subject: [PATCH 03/11] remove stringsAsFactors --- R/read_waterdata_ratings.R | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/R/read_waterdata_ratings.R b/R/read_waterdata_ratings.R index 2c4c7269c..e3b72ba3f 100644 --- a/R/read_waterdata_ratings.R +++ b/R/read_waterdata_ratings.R @@ -204,14 +204,12 @@ parse_ratings_metadata <- function(ratings_df) { if (is.null(raw_comments)) { return(data.frame( header = character(), - value = character(), - stringsAsFactors = FALSE + value = character() )) } com <- data.frame( - line = raw_comments, - stringsAsFactors = FALSE + line = raw_comments ) # remove whitespace @@ -254,8 +252,7 @@ parse_ratings_metadata <- function(ratings_df) { sub("^[A-Za-z0-9_]+\\s*=\\s*", "", kv_flat, perl = TRUE) ) ) - ), - stringsAsFactors = FALSE + ) ) # handle data with colons @@ -277,8 +274,7 @@ parse_ratings_metadata <- function(ratings_df) { trimws( sub("^[A-Z][A-Z _-]+:\\s*", "", colon_lines, perl = TRUE) ) - ), - stringsAsFactors = FALSE + ) ) # parse any lines that don't fit other patterns @@ -298,16 +294,14 @@ parse_ratings_metadata <- function(ratings_df) { trimws( sub("^[A-Z][A-Z _-]+\\s*", "", other_lines, perl = TRUE) ) - ), - stringsAsFactors = FALSE + ) ) # combine into one dataframe to be added to list object final <- rbind( data.frame( header = "WARNING", - value = warning_block, - stringsAsFactors = FALSE + value = warning_block ), pairs_df, date_df, From ef7756ac9d62cf4fa30f3c7cc381efa8f32450cc Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 23 Jun 2026 09:11:37 -0500 Subject: [PATCH 04/11] building the docs --- R/read_waterdata_ratings.R | 2 ++ man/read_waterdata_ratings.Rd | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/read_waterdata_ratings.R b/R/read_waterdata_ratings.R index 6054d6631..cfe024276 100644 --- a/R/read_waterdata_ratings.R +++ b/R/read_waterdata_ratings.R @@ -316,6 +316,8 @@ parse_ratings_metadata <- function(ratings_df) { final <- final[!(final$header == "" & final$value == ""), , drop = FALSE] final <- unique(final) + rownames(final) <- final$header + # final_t <- data.frame(t(final)) rownames(final) <- NULL final diff --git a/man/read_waterdata_ratings.Rd b/man/read_waterdata_ratings.Rd index 4b516e345..c2284e5fd 100644 --- a/man/read_waterdata_ratings.Rd +++ b/man/read_waterdata_ratings.Rd @@ -57,7 +57,13 @@ and return a list of data frames with rating curve data (\code{TRUE}), or to ret just a list of available rating curve files (\code{FALSE}). Default is \code{TRUE}.} } \value{ -List of data frames which contain the requested rating curves. +List of named lists, one per requested rating file. Each element +contains: +\describe{ +\item{ratings}{Data frame of the rating curve.} +\item{metadata}{Data frame of header/value pairs parsed from the comment +attribute of the ratings file.} +} } \description{ Reads current rating table for an active USGS streamgages. More information @@ -89,15 +95,15 @@ ratings_exsa <- read_waterdata_ratings( monitoring_location_id = monitoring_location_id, file_type = "exsa") -head(ratings_exsa[["USGS-01104475.exsa.rdb"]]) -comment(ratings_exsa[["USGS-01104475.exsa.rdb"]])[1:15] +head(ratings_exsa[["USGS-01104475.exsa.rdb"]]$ratings) +ratings_exsa[["USGS-01104475.exsa.rdb"]]$metadata ratings_corr <- read_waterdata_ratings( monitoring_location_id = monitoring_location_id, file_type = "corr") -head(ratings_corr[["USGS-01104460.corr.rdb"]]) -comment(ratings_corr[["USGS-01104460.corr.rdb"]])[1:15] +head(ratings_corr[["USGS-01104460.corr.rdb"]]$ratings) +ratings_corr[["USGS-01104460.corr.rdb"]]$metadata rating_2 <- read_waterdata_ratings( monitoring_location_id = monitoring_location_id, From cb6e1bd7fd93f554cc700786d53403210d9d7bfb Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 23 Jun 2026 15:44:16 -0500 Subject: [PATCH 05/11] remove functions that don't work --- R/readNGWMNdata.R | 226 ---------------------------------------------- _pkgdown.yml | 3 +- 2 files changed, 2 insertions(+), 227 deletions(-) delete mode 100644 R/readNGWMNdata.R diff --git a/R/readNGWMNdata.R b/R/readNGWMNdata.R deleted file mode 100644 index f9c9a621a..000000000 --- a/R/readNGWMNdata.R +++ /dev/null @@ -1,226 +0,0 @@ -#' Import data from the National Groundwater Monitoring Network. -#' -#' Only water level data and site locations and names are currently available through the web service. -#' @param service char Service for the request - "observation" and "featureOfInterest" are implemented. -#' @param \dots Other parameters to supply, namely `siteNumbers` or `bbox` -#' @param asDateTime logical if `TRUE`, will convert times to POSIXct format. Currently defaults to -#' `FALSE` since time zone information is not included. -#' @param tz character to set timezone attribute of dateTime. Default is "UTC", and converts the -#' date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -#' Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -#' "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -#' "America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also `OlsonNames()` -#' for more information on time zones. -#' @export -readNGWMNdata <- function(service, ..., asDateTime = TRUE, tz = "UTC") { - .Deprecated( - new = "read_ngwmn_water_level", - package = "dataRetrieval", - msg = "Updated NGWMN APIs will use read_ngwmn set of functions." - ) - - dots <- convertLists(...) - - match.arg(service, c("observation", "featureOfInterest")) - - if (service == "observation") { - # these attributes are pulled out and saved when doing binds to be reattached - attrs <- c( - "url", - "gml:identifier", - "generationDate", - "responsibleParty", - "contact" - ) - featureID <- stats::na.omit(gsub(":", ".", dots[["siteNumbers"]])) - - obs_list <- vector("list", length(featureID)) - attr_list <- vector("list", length(featureID)) - for (idx in seq_along(featureID)) { - obsFID <- retrieveObservation( - featureID = featureID[idx], - asDateTime, - attrs, - tz = tz - ) - attr_list[[idx]] <- saveAttrs(attrs, obsFID) - obs_list[[idx]] <- removeAttrs(attrs, obsFID) - } - allObs <- Reduce(r_bind_dr, obs_list, init = data.frame()) - allAttrs <- Reduce(r_bind_dr, attr_list, init = data.frame()) - - allSites <- tryCatch( - { - retrieveFeatureOfInterest(featureID = featureID) - }, - error = function(cond) { - return(NULL) - } - ) - - if (!is.null(allSites)) { - attr(allObs, "siteInfo") <- allSites - } - - attr(allObs, "other") <- allAttrs - returnData <- allObs - } else if (service == "featureOfInterest") { - if ("siteNumbers" %in% names(dots)) { - featureID <- stats::na.omit(gsub(":", ".", dots[["siteNumbers"]])) - allSites <- tryCatch({ - retrieveFeatureOfInterest(featureID = featureID) - }) - } - - if ("bbox" %in% names(dots)) { - allSites <- tryCatch({ - retrieveFeatureOfInterest(bbox = dots[["bbox"]]) - }) - } - returnData <- allSites - } - - return(returnData) -} - -#' Retrieve groundwater levels from the National Ground Water Monitoring Network. -#' -#' @param siteNumbers character Vector of feature IDs formatted with agency code and site number -#' separated by a period or semicolon, e.g. `USGS.404159100494601`. -#' @param asDateTime logical Should dates and times be converted to date/time objects, -#' or returned as character? Defaults to `TRUE`. Must be set to `FALSE` if a site -#' contains non-standard dates. -#' @param tz character to set timezone attribute of dateTime. Default is "UTC", and converts the -#' date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -#' Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -#' "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -#' "America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also `OlsonNames()` -#' for more information on time zones. -#' @export -readNGWMNlevels <- function(siteNumbers, asDateTime = TRUE, tz = "UTC") { - data <- readNGWMNdata( - siteNumbers = siteNumbers, - service = "observation", - asDateTime = asDateTime, - tz = tz - ) - return(data) -} - -#' Retrieve site data from the National Ground Water Monitoring Network. -#' -#' @param siteNumbers character Vector of feature IDs formatted with agency code and site number -#' separated by a period or semicolon, e.g. `USGS.404159100494601`. -#' -#' @export -#' @return A data frame the following columns: -#' #' \tabular{lll}{ -#' Name \tab Type \tab Description \cr -#' site \tab char \tab Site FID \cr -#' description \tab char \tab Site description \cr -#' dec_lat_va, dec_lon_va \tab numeric \tab Site latitude and longitude \cr -#' } - -readNGWMNsites <- function(siteNumbers) { - sites <- readNGWMNdata( - siteNumbers = siteNumbers, - service = "featureOfInterest" - ) - return(sites) -} - -retrieveObservation <- function(featureID, asDateTime, attrs, tz) { - baseURL <- httr2::request(pkg.env[["NGWMN"]]) - baseURL <- httr2::req_url_query( - baseURL, - request = "GetObservation", - service = "SOS", - version = "2.0.0", - observedProperty = "urn:ogc:def:property:OGC:GroundWaterLevel", - responseFormat = "text/xml", - featureOfInterest = paste("VW_GWDP_GEOSERVER", featureID, sep = ".") - ) - - returnData <- importNGWMN(baseURL, asDateTime = asDateTime, tz = tz) - if (nrow(returnData) == 0) { - # need to add NA attributes, so they aren't messed up when stored as DFs - attr(returnData, "gml:identifier") <- NA - attr(returnData, "generationDate") <- NA - } - - # mutate removes the attributes, need to save and append - attribs <- saveAttrs(attrs, returnData) - if (nrow(returnData) > 0) { - # tack on site number - siteNum <- rep(sub(".*\\.", "", featureID), nrow(returnData)) - returnData$site <- siteNum - numCol <- ncol(returnData) - returnData <- returnData[, c(numCol, 1:(numCol - 1))] # move siteNum to the left - } - attributes(returnData) <- c(attributes(returnData), as.list(attribs)) - - return(returnData) -} - -# retrieve feature of interest -# could allow pass through srsName - needs to be worked in higher-up in dots -retrieveFeatureOfInterest <- function( - ..., - asDateTime, - srsName = "urn:ogc:def:crs:EPSG::4269" -) { - values <- convertLists(...) - - baseURL <- httr2::request(pkg.env[["NGWMN"]]) - baseURL <- httr2::req_url_query( - baseURL, - request = "GetFeatureOfInterest", - service = "SOS", - version = "2.0.0", - responseFormat = "text/xml" - ) - - if ("featureID" %in% names(values)) { - features <- paste("VW_GWDP_GEOSERVER", values[["featureID"]], sep = ".") - - baseURL <- httr2::req_url_query( - baseURL, - featureOfInterest = features, - .multi = "comma" - ) - } else if ("bbox" %in% names(values)) { - baseURL <- httr2::req_url_query( - baseURL, - bbox = paste(values[["bbox"]], collapse = ","), - srsName = srsName - ) - } else { - stop("Geographical filter not specified. Please use siteNumbers or bbox") - } - - siteDF <- importNGWMN(baseURL, asDateTime, tz = "") - attr(siteDF, "url") <- baseURL$url - attr(siteDF, "queryTime") <- Sys.time() - return(siteDF) -} - - -# save specified attributes from a data frame -saveAttrs <- function(attrs, df) { - attribs <- sapply(attrs, function(x) attr(df, x)) - if (is.vector(attribs)) { - toReturn <- as.data.frame(t(attribs), stringsAsFactors = FALSE) - } else { - # don't need to transpose - toReturn <- as.data.frame(attribs, stringsAsFactors = FALSE) - } - return(toReturn) -} - -# strip specified attributes from a data frame -removeAttrs <- function(attrs, df) { - for (a in attrs) { - attr(df, a) <- NULL - } - return(df) -} diff --git a/_pkgdown.yml b/_pkgdown.yml index 8af889bdc..cde33ded4 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -85,7 +85,6 @@ reference: - read_waterdata - summarize_waterdata_samples - check_waterdata_sample_params - - get_ogc_params - read_waterdata_channel - read_waterdata_field_meta - read_waterdata_combined_meta @@ -124,6 +123,7 @@ reference: - read_ngwmn_providers - read_ngwmn_well_construction - read_ngwmn_lithology + - read_ngwmn - title: Network Linked Data Index desc: Functions to interface with the NLDI. contents: @@ -163,3 +163,4 @@ reference: - getWebServiceData - is_dataRetrieval_user - checkWQPdates + - get_ogc_params From ddaca79ee2c70380a10c8d315d6caaa780e069a8 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 23 Jun 2026 15:50:03 -0500 Subject: [PATCH 06/11] Cleanup pkgdown --- NAMESPACE | 3 --- _pkgdown.yml | 2 +- man/readNGWMNdata.Rd | 26 -------------------------- man/readNGWMNlevels.Rd | 26 -------------------------- man/readNGWMNsites.Rd | 24 ------------------------ 5 files changed, 1 insertion(+), 80 deletions(-) delete mode 100644 man/readNGWMNdata.Rd delete mode 100644 man/readNGWMNlevels.Rd delete mode 100644 man/readNGWMNsites.Rd diff --git a/NAMESPACE b/NAMESPACE index 9b96ffa72..45be56a32 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,9 +27,6 @@ export(pCodeToName) export(parameterCdFile) export(parse_WQP) export(pcode_to_name) -export(readNGWMNdata) -export(readNGWMNlevels) -export(readNGWMNsites) export(readNWISdata) export(readNWISdv) export(readNWISpCode) diff --git a/_pkgdown.yml b/_pkgdown.yml index cde33ded4..2adf3191a 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -118,7 +118,7 @@ reference: - title: National Ground-Water Monitoring Network desc: Functions to retrieve NGWMN data. contents: - - read_ngwmn_water_levels + - read_ngwmn_water_level - read_ngwmn_sites - read_ngwmn_providers - read_ngwmn_well_construction diff --git a/man/readNGWMNdata.Rd b/man/readNGWMNdata.Rd deleted file mode 100644 index b56d0dbe6..000000000 --- a/man/readNGWMNdata.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNGWMNdata.R -\name{readNGWMNdata} -\alias{readNGWMNdata} -\title{Import data from the National Groundwater Monitoring Network.} -\usage{ -readNGWMNdata(service, ..., asDateTime = TRUE, tz = "UTC") -} -\arguments{ -\item{service}{char Service for the request - "observation" and "featureOfInterest" are implemented.} - -\item{\dots}{Other parameters to supply, namely \code{siteNumbers} or \code{bbox}} - -\item{asDateTime}{logical if \code{TRUE}, will convert times to POSIXct format. Currently defaults to -\code{FALSE} since time zone information is not included.} - -\item{tz}{character to set timezone attribute of dateTime. Default is "UTC", and converts the -date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -"America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -"America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also \code{OlsonNames()} -for more information on time zones.} -} -\description{ -Only water level data and site locations and names are currently available through the web service. -} diff --git a/man/readNGWMNlevels.Rd b/man/readNGWMNlevels.Rd deleted file mode 100644 index 64637e52e..000000000 --- a/man/readNGWMNlevels.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNGWMNdata.R -\name{readNGWMNlevels} -\alias{readNGWMNlevels} -\title{Retrieve groundwater levels from the National Ground Water Monitoring Network.} -\usage{ -readNGWMNlevels(siteNumbers, asDateTime = TRUE, tz = "UTC") -} -\arguments{ -\item{siteNumbers}{character Vector of feature IDs formatted with agency code and site number -separated by a period or semicolon, e.g. \code{USGS.404159100494601}.} - -\item{asDateTime}{logical Should dates and times be converted to date/time objects, -or returned as character? Defaults to \code{TRUE}. Must be set to \code{FALSE} if a site -contains non-standard dates.} - -\item{tz}{character to set timezone attribute of dateTime. Default is "UTC", and converts the -date times to UTC, properly accounting for daylight savings times based on the data's provided time zone offset. -Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", -"America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", -"America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also \code{OlsonNames()} -for more information on time zones.} -} -\description{ -Retrieve groundwater levels from the National Ground Water Monitoring Network. -} diff --git a/man/readNGWMNsites.Rd b/man/readNGWMNsites.Rd deleted file mode 100644 index 4b5c92bef..000000000 --- a/man/readNGWMNsites.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readNGWMNdata.R -\name{readNGWMNsites} -\alias{readNGWMNsites} -\title{Retrieve site data from the National Ground Water Monitoring Network.} -\usage{ -readNGWMNsites(siteNumbers) -} -\arguments{ -\item{siteNumbers}{character Vector of feature IDs formatted with agency code and site number -separated by a period or semicolon, e.g. \code{USGS.404159100494601}.} -} -\value{ -A data frame the following columns: -#' \tabular{lll}{ -Name \tab Type \tab Description \cr -site \tab char \tab Site FID \cr -description \tab char \tab Site description \cr -dec_lat_va, dec_lon_va \tab numeric \tab Site latitude and longitude \cr -} -} -\description{ -Retrieve site data from the National Ground Water Monitoring Network. -} From c7fe17916b7431511cceabe030b67b1310776d59 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Wed, 24 Jun 2026 11:47:24 -0500 Subject: [PATCH 07/11] Allow geometry in continuous --- DESCRIPTION | 5 ++++- R/read_waterdata_continuous.R | 4 +++- man/read_waterdata_combined_meta.Rd | 4 ++-- man/read_waterdata_continuous.Rd | 14 ++++++++++++++ man/read_waterdata_field_meta.Rd | 2 +- man/read_waterdata_latest_continuous.Rd | 2 +- man/read_waterdata_latest_daily.Rd | 2 +- man/read_waterdata_monitoring_location.Rd | 2 +- man/read_waterdata_peaks.Rd | 2 +- man/read_waterdata_ts_meta.Rd | 4 ++-- 10 files changed, 30 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 101d0fc5c..4df9e8d4c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,10 @@ Authors@R: c( comment=c(ORCID = "0000-0001-5396-1583")), person("Michael", "Mahoney", role="ctb", email = "mjmahoney@usgs.gov", - comment=c(ORCID = "0000-0003-2402-304X")) + comment=c(ORCID = "0000-0003-2402-304X")), + person("Matthew", "Conlon", role="ctb", + email = "mconlon@usgs.gov", + comment=c(ORCID = "0000-0001-8266-9610")) ) Description: Collection of functions to help retrieve U.S. Geological Survey and U.S. Environmental Protection Agency water quality and diff --git a/R/read_waterdata_continuous.R b/R/read_waterdata_continuous.R index d9291e560..0f260ff7b 100644 --- a/R/read_waterdata_continuous.R +++ b/R/read_waterdata_continuous.R @@ -35,6 +35,7 @@ #' @param \dots Not used. Included to help differentiate official Water Data API arguments #' from more seldom used, optional dataRetrieval-specific arguments. #' @inheritParams check_arguments_non_api +#' @inheritParams check_arguments_api #' #' @details #' You can also use a vector of length 2 for any time queries (such as time @@ -120,6 +121,8 @@ read_waterdata_continuous <- function( value = NA, last_modified = NA_character_, time = NA_character_, + skipGeometry = TRUE, + bbox = NA, ..., convertType = getOption("dataRetrieval.convertType"), limit = getOption("dataRetrieval.limit"), @@ -132,7 +135,6 @@ read_waterdata_continuous <- function( rlang::check_dots_empty() args <- mget(names(formals())) - args[["skipGeometry"]] <- TRUE return_list <- get_ogc_data(args, output_id, service) diff --git a/man/read_waterdata_combined_meta.Rd b/man/read_waterdata_combined_meta.Rd index 4e7a3519a..f51477936 100644 --- a/man/read_waterdata_combined_meta.Rd +++ b/man/read_waterdata_combined_meta.Rd @@ -185,7 +185,7 @@ See also Details below for more information.} \item{site_type}{A description of the hydrologic setting of the monitoring location. A list of codes is available at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/site-types/items}.} -\item{hydrologic_unit_code}{The United States is divided and sub-divided into successively smaller hydrologic units which are classified into four levels: regions, sub-regions, accounting units, and cataloging units. The hydrologic units are arranged within each other, from the smallest (cataloging units) to the largest (regions). Each hydrologic unit is identified by a unique hydrologic unit code (HUC) consisting of two to eight digits based on the four levels of classification in the hydrologic unit system.} +\item{hydrologic_unit_code}{The hydrologic unit code (HUC) for the monitoring location. Supports prefix matching — querying with a shorter HUC (e.g. "04") matches all locations within that hydrologic region.} \item{basin_code}{The Basin Code or "drainage basin code" is a two-digit code that further subdivides the 8-digit hydrologic-unit code. The drainage basin code is defined by the USGS State Office where the monitoring location is located.} @@ -237,7 +237,7 @@ See also Details below for more information.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, monitoring_location_id, agency_code, agency_name, monitoring_location_number, monitoring_location_name, district_code, country_code, country_name, state_code, state_name, county_code, county_name, minor_civil_division_code, site_type_code, site_type, hydrologic_unit_code, basin_code, altitude, altitude_accuracy, altitude_method_code, altitude_method_name, vertical_datum, vertical_datum_name, horizontal_positional_accuracy_code, horizontal_positional_accuracy, horizontal_position_method_code, horizontal_position_method_name, original_horizontal_datum, original_horizontal_datum_name, drainage_area, contributing_drainage_area, time_zone_abbreviation, uses_daylight_savings, construction_date, aquifer_code, national_aquifer_code, aquifer_type_code, well_constructed_depth, hole_constructed_depth, depth_source_code, field_measurement_id, unit_of_measure, parameter_name, parameter_code, statistic_id, last_modified, begin, end, data_type, computation_identifier, thresholds, sublocation_identifier, primary, web_description, parameter_description, parent_time_series_id. +geometry, monitoring_location_id, agency_code, agency_name, monitoring_location_number, monitoring_location_name, district_code, country_code, country_name, state_code, state_name, county_code, county_name, minor_civil_division_code, site_type_code, site_type, hydrologic_unit_code, basin_code, altitude, altitude_accuracy, altitude_method_code, altitude_method_name, vertical_datum, vertical_datum_name, horizontal_positional_accuracy_code, horizontal_positional_accuracy, horizontal_position_method_code, horizontal_position_method_name, original_horizontal_datum, original_horizontal_datum_name, drainage_area, contributing_drainage_area, time_zone_abbreviation, uses_daylight_savings, construction_date, aquifer_code, national_aquifer_code, aquifer_type_code, well_constructed_depth, hole_constructed_depth, depth_source_code, field_measurement_id, unit_of_measure, parameter_name, parameter_code, statistic_id, last_modified, begin, end, data_type, computation_identifier, thresholds, sublocation_identifier, primary, web_description, parameter_description, parent_time_series_id, data_gap_interval, reading_type. The default (\code{NA}) will return all columns of the data.} \item{skipGeometry}{This parameter can be used to skip response geometries for diff --git a/man/read_waterdata_continuous.Rd b/man/read_waterdata_continuous.Rd index e722a5ede..d7506db76 100644 --- a/man/read_waterdata_continuous.Rd +++ b/man/read_waterdata_continuous.Rd @@ -15,6 +15,8 @@ read_waterdata_continuous( value = NA, last_modified = NA_character_, time = NA_character_, + skipGeometry = TRUE, + bbox = NA, ..., convertType = getOption("dataRetrieval.convertType"), limit = getOption("dataRetrieval.limit"), @@ -76,6 +78,18 @@ Only features that have a \code{time} that intersects the value of datetime are See also Details below for more information.} +\item{skipGeometry}{This parameter can be used to skip response geometries for +each feature. The returning object will be a data frame with no spatial +information. The default \code{NA} will not specify the argument in the request.} + +\item{bbox}{Only features that have a geometry that intersects the bounding +box are selected.The bounding box is provided as four or six numbers, depending +on whether the coordinate reference system includes a vertical axis (height or +depth). Coordinates are assumed to be in crs 4326. The expected format is a numeric +vector structured: c(xmin,ymin,xmax,ymax). +Another way to think of it is c(Western-most longitude, +Southern-most latitude, Eastern-most longitude, Northern-most longitude).} + \item{\dots}{Not used. Included to help differentiate official Water Data API arguments from more seldom used, optional dataRetrieval-specific arguments.} diff --git a/man/read_waterdata_field_meta.Rd b/man/read_waterdata_field_meta.Rd index 1ecfe588f..30bec39af 100644 --- a/man/read_waterdata_field_meta.Rd +++ b/man/read_waterdata_field_meta.Rd @@ -83,7 +83,7 @@ See also Details below for more information.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, field_measurement_id, monitoring_location_id, parameter_code, parameter_name, parameter_description, begin, end, last_modified. +geometry, field_measurement_id, reading_type, monitoring_location_id, parameter_code, parameter_name, parameter_description, begin, end, last_modified. The default (\code{NA}) will return all columns of the data.} \item{skipGeometry}{This parameter can be used to skip response geometries for diff --git a/man/read_waterdata_latest_continuous.Rd b/man/read_waterdata_latest_continuous.Rd index e980a60e6..5af72c3f8 100644 --- a/man/read_waterdata_latest_continuous.Rd +++ b/man/read_waterdata_latest_continuous.Rd @@ -36,7 +36,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, latest_continuous_id, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. +geometry, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint. diff --git a/man/read_waterdata_latest_daily.Rd b/man/read_waterdata_latest_daily.Rd index 6eb5a386b..3989eb396 100644 --- a/man/read_waterdata_latest_daily.Rd +++ b/man/read_waterdata_latest_daily.Rd @@ -41,7 +41,7 @@ Multiple statistic_ids can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, latest_daily_id, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. +geometry, time_series_id, monitoring_location_id, parameter_code, statistic_id, time, value, unit_of_measure, approval_status, qualifier, last_modified. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint. diff --git a/man/read_waterdata_monitoring_location.Rd b/man/read_waterdata_monitoring_location.Rd index 5072a644f..be42815ce 100644 --- a/man/read_waterdata_monitoring_location.Rd +++ b/man/read_waterdata_monitoring_location.Rd @@ -88,7 +88,7 @@ Multiple monitoring_location_ids can be requested as a character vector.} \item{site_type}{A description of the hydrologic setting of the monitoring location. A list of codes is available at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/site-types/items}.} -\item{hydrologic_unit_code}{The United States is divided and sub-divided into successively smaller hydrologic units which are classified into four levels: regions, sub-regions, accounting units, and cataloging units. The hydrologic units are arranged within each other, from the smallest (cataloging units) to the largest (regions). Each hydrologic unit is identified by a unique hydrologic unit code (HUC) consisting of two to eight digits based on the four levels of classification in the hydrologic unit system.} +\item{hydrologic_unit_code}{The hydrologic unit code (HUC) for the monitoring location. Supports prefix matching — querying with a shorter HUC (e.g. "04") matches all locations within that hydrologic region.} \item{basin_code}{The Basin Code or "drainage basin code" is a two-digit code that further subdivides the 8-digit hydrologic-unit code. The drainage basin code is defined by the USGS State Office where the monitoring location is located.} diff --git a/man/read_waterdata_peaks.Rd b/man/read_waterdata_peaks.Rd index 830040abd..260b36548 100644 --- a/man/read_waterdata_peaks.Rd +++ b/man/read_waterdata_peaks.Rd @@ -42,7 +42,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, time_series_id, monitoring_location_id, parameter_code, peak_id, unit_of_measure, value, last_modified, time, water_year, year, month, day, time_of_day, peak_since, qualifier. +geometry, time_series_id, monitoring_location_id, parameter_code, unit_of_measure, value, last_modified, time, water_year, year, month, day, time_of_day, peak_since, qualifier. The default (\code{NA}) will return all columns of the data.} \item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint.} diff --git a/man/read_waterdata_ts_meta.Rd b/man/read_waterdata_ts_meta.Rd index 3188d4b8b..dd4c80cb2 100644 --- a/man/read_waterdata_ts_meta.Rd +++ b/man/read_waterdata_ts_meta.Rd @@ -49,7 +49,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, time_series_id, unit_of_measure, parameter_name, parameter_code, statistic_id, hydrologic_unit_code, state_name, last_modified, begin, end, begin_utc, end_utc, computation_period_identifier, computation_identifier, thresholds, sublocation_identifier, primary, monitoring_location_id, web_description, parameter_description, parent_time_series_id. +geometry, time_series_id, unit_of_measure, parameter_name, parameter_code, statistic_id, hydrologic_unit_code, state_name, last_modified, begin, end, begin_utc, end_utc, computation_period_identifier, computation_identifier, thresholds, sublocation_identifier, primary, monitoring_location_id, web_description, parameter_description, parent_time_series_id, data_gap_interval. The default (\code{NA}) will return all columns of the data.} \item{statistic_id}{A code corresponding to the statistic an observation represents. Example codes include 00001 (max), 00002 (min), and 00003 (mean). A complete list of codes and their descriptions can be found at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/statistic-codes/items}. @@ -99,7 +99,7 @@ Only features that have a \code{end_utc} that intersects the value of datetime a See also Details below for more information.} -\item{hydrologic_unit_code}{The United States is divided and sub-divided into successively smaller hydrologic units which are classified into four levels: regions, sub-regions, accounting units, and cataloging units. The hydrologic units are arranged within each other, from the smallest (cataloging units) to the largest (regions). Each hydrologic unit is identified by a unique hydrologic unit code (HUC) consisting of two to eight digits based on the four levels of classification in the hydrologic unit system.} +\item{hydrologic_unit_code}{The hydrologic unit code (HUC) for the monitoring location. Supports prefix matching — querying with a shorter HUC (e.g. "04") matches all locations within that hydrologic region.} \item{state_name}{The name of the state or state equivalent in which the monitoring location is located.} From bbfcca7013702baa2ff67a3379fa3cd5de91e393 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Wed, 24 Jun 2026 11:57:27 -0500 Subject: [PATCH 08/11] fix note --- R/read_waterdata_continuous.R | 1 - man/read_waterdata_continuous.Rd | 2 -- 2 files changed, 3 deletions(-) diff --git a/R/read_waterdata_continuous.R b/R/read_waterdata_continuous.R index 0f260ff7b..eff8cc876 100644 --- a/R/read_waterdata_continuous.R +++ b/R/read_waterdata_continuous.R @@ -8,7 +8,6 @@ #' for new direct download functions that are expected to be available sometime #' in 2026. #' -#' Geometry output is not supported in the continuous data API endpoint. #' #' @export #' @param monitoring_location_id `r get_ogc_params("continuous")$monitoring_location_id` diff --git a/man/read_waterdata_continuous.Rd b/man/read_waterdata_continuous.Rd index d7506db76..cb48d15b6 100644 --- a/man/read_waterdata_continuous.Rd +++ b/man/read_waterdata_continuous.Rd @@ -128,8 +128,6 @@ a single request. If no "time" is specified, the service will return the last single year of data. If this is a bottleneck, please check back for new direct download functions that are expected to be available sometime in 2026. - -Geometry output is not supported in the continuous data API endpoint. } \details{ You can also use a vector of length 2 for any time queries (such as time From e94f179c8e480d1c30469dae1fc9b12c8d98509b Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 7 Jul 2026 13:56:35 -0500 Subject: [PATCH 09/11] latest field --- NAMESPACE | 1 + R/AAA.R | 5 +- R/read_waterdata_latest_field.R | 88 +++++++++++++++ _pkgdown.yml | 1 + man/read_waterdata_latest_field.Rd | 172 +++++++++++++++++++++++++++++ 5 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 R/read_waterdata_latest_field.R create mode 100644 man/read_waterdata_latest_field.Rd diff --git a/NAMESPACE b/NAMESPACE index 45be56a32..57aa60499 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,6 +55,7 @@ export(read_waterdata_field_measurements) export(read_waterdata_field_meta) export(read_waterdata_latest_continuous) export(read_waterdata_latest_daily) +export(read_waterdata_latest_field) export(read_waterdata_metadata) export(read_waterdata_monitoring_location) export(read_waterdata_parameter_codes) diff --git a/R/AAA.R b/R/AAA.R index ad96e4649..1cd88cada 100644 --- a/R/AAA.R +++ b/R/AAA.R @@ -3,7 +3,9 @@ pkg.env <- new.env() .onLoad <- function(libname, pkgname) { suppressMessages(setAccess("public")) pkg.env$local_sf <- requireNamespace("sf", quietly = TRUE) - options("dataRetrieval.nldi_base" = "https://api.water.usgs.gov/nldi/linked-data/") + options( + "dataRetrieval.nldi_base" = "https://api.water.usgs.gov/nldi/linked-data/" + ) options("dataRetrieval.api_version" = "v0") options("dataRetrieval.api_version_stat" = "v0") options("dataRetrieval.attach_request" = TRUE) @@ -21,6 +23,7 @@ pkg.env <- new.env() "latest-continuous", "field-measurements", "latest-daily", + "latest-field-measurements", "continuous", "field-measurements-metadata", "combined-metadata", diff --git a/R/read_waterdata_latest_field.R b/R/read_waterdata_latest_field.R new file mode 100644 index 000000000..eece4a905 --- /dev/null +++ b/R/read_waterdata_latest_field.R @@ -0,0 +1,88 @@ +#' Get Latest USGS field Data +#' +#' @description `r get_description("latest-field-measurements")` +#' +#' @export +#' @param monitoring_location_id `r get_ogc_params("latest-field-measurements")$monitoring_location_id` +#' Multiple monitoring_location_ids can be requested as a character vector. +#' @param parameter_code `r get_ogc_params("latest-field-measurements")$parameter_code` +#' Multiple parameter_codes can be requested as a character vector. +#' @param statistic_id `r get_ogc_params("latest-field-measurements")$statistic_id` +#' Multiple statistic_ids can be requested as a character vector. +#' @param time `r get_ogc_params("latest-field-measurements")$time` +#' +#' See also Details below for more information. +#' @param value `r get_ogc_params("latest-field-measurements")$value` +#' @param unit_of_measure `r get_ogc_params("latest-field-measurements")$unit_of_measure` +#' @param approval_status `r get_ogc_params("latest-field-measurements")$approval_status` +#' @param last_modified `r get_ogc_params("latest-field-measurements")$last_modified` +#' +#' See also Details below for more information. +#' @param time_series_id `r get_ogc_params("latest-field-measurements")$time_series_id` +#' Multiple time_series_ids can be requested as a character vector. +#' @param qualifier `r get_ogc_params("latest-field-measurements")$qualifier` +#' @param properties A vector of requested columns to be returned from the query. +#' Available options are: +#' `r dataRetrieval:::get_properties_for_docs("latest-field-measurements", "latest_field_id")`. +#' The default (`NA`) will return all columns of the data. +#' +#' @inheritParams check_arguments_api +#' @inheritParams check_arguments_non_api +#' @inherit read_waterdata_continuous details +#' +#' @examplesIf is_dataRetrieval_user() +#' +#' \donttest{ +#' site <- "USGS-02238500" +#' pcode <- "00060" +#' dv_data_sf <- read_waterdata_latest_field(monitoring_location_id = site, +#' parameter_code = pcode) +#' +#' dv_data_last_modified <- read_waterdata_latest_field(monitoring_location_id = site, +#' parameter_code = pcode, +#' last_modified = "P7D") +#' +#' dv_data_trim <- read_waterdata_latest_field(monitoring_location_id = site, +#' parameter_code = pcode, +#' properties = c("monitoring_location_id", +#' "value", +#' "time")) +#' +#' dv_data <- read_waterdata_latest_field(monitoring_location_id = site, +#' parameter_code = pcode, +#' skipGeometry = TRUE) +#' +#' multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01491000", +#' "USGS-01645000")) +#' +#' } +read_waterdata_latest_field <- function( + monitoring_location_id = NA_character_, + parameter_code = NA_character_, + statistic_id = NA_character_, + properties = NA_character_, + time_series_id = NA_character_, + approval_status = NA_character_, + unit_of_measure = NA_character_, + qualifier = NA_character_, + value = NA, + last_modified = NA_character_, + skipGeometry = NA, + time = NA_character_, + bbox = NA, + ..., + convertType = getOption("dataRetrieval.convertType"), + no_paging = getOption("dataRetrieval.no_paging"), + limit = getOption("dataRetrieval.limit"), + chunk_size = getOption("dataRetrieval.site_chunk_size_meta"), + attach_request = getOption("dataRetrieval.attach_request") +) { + service <- "latest-field-measurements" + output_id <- "latest_field_id" + rlang::check_dots_empty() + + args <- mget(names(formals())) + return_list <- get_ogc_data(args, output_id, service) + + return(return_list) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 2adf3191a..c6e298089 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -79,6 +79,7 @@ reference: - read_waterdata_monitoring_location - read_waterdata_latest_continuous - read_waterdata_latest_daily + - read_waterdata_latest_field - read_waterdata_field_measurements - read_waterdata_parameter_codes - read_waterdata_metadata diff --git a/man/read_waterdata_latest_field.Rd b/man/read_waterdata_latest_field.Rd new file mode 100644 index 000000000..a05dc71e9 --- /dev/null +++ b/man/read_waterdata_latest_field.Rd @@ -0,0 +1,172 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_waterdata_latest_field.R +\name{read_waterdata_latest_field} +\alias{read_waterdata_latest_field} +\title{Get Latest USGS field Data} +\usage{ +read_waterdata_latest_field( + monitoring_location_id = NA_character_, + parameter_code = NA_character_, + statistic_id = NA_character_, + properties = NA_character_, + time_series_id = NA_character_, + approval_status = NA_character_, + unit_of_measure = NA_character_, + qualifier = NA_character_, + value = NA, + last_modified = NA_character_, + skipGeometry = NA, + time = NA_character_, + bbox = NA, + ..., + convertType = getOption("dataRetrieval.convertType"), + no_paging = getOption("dataRetrieval.no_paging"), + limit = getOption("dataRetrieval.limit"), + chunk_size = getOption("dataRetrieval.site_chunk_size_meta"), + attach_request = getOption("dataRetrieval.attach_request") +) +} +\arguments{ +\item{monitoring_location_id}{A unique identifier representing a single monitoring location. This corresponds to the \code{id} field in the \code{monitoring-locations} endpoint. Monitoring location IDs are created by combining the agency code of the agency responsible for the monitoring location (e.g. USGS) with the ID number of the monitoring location (e.g. 02238500), separated by a hyphen (e.g. USGS-02238500). + +Multiple monitoring_location_ids can be requested as a character vector.} + +\item{parameter_code}{Parameter codes are 5-digit codes used to identify the constituent measured and the units of measure. A complete list of parameter codes and associated groupings can be found at \url{https://api.waterdata.usgs.gov/ogcapi/v0/collections/parameter-codes/items}. + +Multiple parameter_codes can be requested as a character vector.} + +\item{statistic_id}{Multiple statistic_ids can be requested as a character vector.} + +\item{properties}{A vector of requested columns to be returned from the query. +Available options are: +geometry, field_measurements_series_id, field_visit_id, parameter_code, monitoring_location_id, observing_procedure_code, observing_procedure, value, unit_of_measure, time, qualifier, vertical_datum, approval_status, measuring_agency, last_modified, control_condition, measurement_rated, year, month, day, time_of_day. +The default (\code{NA}) will return all columns of the data.} + +\item{time_series_id}{Multiple time_series_ids can be requested as a character vector.} + +\item{approval_status}{Some of the data that you have obtained from this U.S. Geological Survey database may not have received Director's approval. Any such data values are qualified as provisional and are subject to revision. Provisional data are released on the condition that neither the USGS nor the United States Government may be held liable for any damages resulting from its use. This field reflects the approval status of each record, and is either "Approved", meaining processing review has been completed and the data is approved for publication, or "Provisional" and subject to revision. For more information about provisional data, go to \url{https://waterdata.usgs.gov/provisional-data-statement/}.} + +\item{unit_of_measure}{A human-readable description of the units of measurement associated with an observation.} + +\item{qualifier}{This field indicates any qualifiers associated with an observation, for instance if a sensor may have been impacted by ice or if values were estimated.} + +\item{value}{The value of the observation. Values are transmitted as strings in the JSON response format in order to preserve precision.} + +\item{last_modified}{The last time a record was refreshed in our database. This may happen due to regular operational processes and does not necessarily indicate anything about the measurement has changed. +You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). +Examples: +\itemize{ +\item A date-time: "2018-02-12T23:20:50Z" +\item A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z" +\item Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z" +\item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours +} + +Only features that have a \code{last_modified} that intersects the value of datetime are selected. + +See also Details below for more information.} + +\item{skipGeometry}{This parameter can be used to skip response geometries for +each feature. The returning object will be a data frame with no spatial +information. The default \code{NA} will not specify the argument in the request.} + +\item{time}{The date an observation represents. You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). +Examples: +\itemize{ +\item A date-time: "2018-02-12T23:20:50Z" +\item A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z" +\item Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z" +\item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours +} + +Only features that have a \code{time} that intersects the value of datetime are selected. If a feature has multiple temporal properties, it is the decision of the server whether only a single temporal property is used to determine the extent or all relevant temporal properties. + +See also Details below for more information.} + +\item{bbox}{Only features that have a geometry that intersects the bounding +box are selected.The bounding box is provided as four or six numbers, depending +on whether the coordinate reference system includes a vertical axis (height or +depth). Coordinates are assumed to be in crs 4326. The expected format is a numeric +vector structured: c(xmin,ymin,xmax,ymax). +Another way to think of it is c(Western-most longitude, +Southern-most latitude, Eastern-most longitude, Northern-most longitude).} + +\item{...}{Not used. Included to help differentiate official Water Data API arguments +from more seldom used, optional dataRetrieval-specific arguments.} + +\item{convertType}{logical, defaults to TRUE. +If \code{TRUE}, the function will convert the data to dates, any qualifiers to string +vector and reorder the returned data frame.} + +\item{no_paging}{logical, defaults to FALSE. +If \code{TRUE}, the data will +be requested from a native csv format. This can be dangerous because the +data will cut off at 50,000 rows without indication that more data +is available. Use \code{TRUE} with caution.} + +\item{limit}{numeric, The optional limit parameter is used to control the subset of the +selected features that should be returned in each page. The maximum allowable +limit is 50,000. It may be beneficial to set this number lower if your internet +connection is spotty. The default (\code{NA}) will set the limit to the maximum +allowable limit for the service.} + +\item{chunk_size}{Number of monitoring_location_ids to chunk requests into. +The default for functions that don't generally return long-term data records +is 250, while +the default for time series functions is +10. +Setting to \code{NA} will eliminate site chunking, giving users full control.} + +\item{attach_request}{logical, defaults to TRUE. +If set to \code{TRUE}, the full request sent to the Water Data API is attached +as an attribute to the data set.} +} +\description{ +Field measurements are physically measured values collected during a visit to the monitoring location. Field measurements consist of measurements of gage height and discharge, and readings of groundwater levels, and are primarily used as calibration readings for the automated sensors collecting continuous data. They are collected at a low frequency, and delivery of the data in WDFN may be delayed due to data processing time. +} +\details{ +You can also use a vector of length 2 for any time queries (such as time +or last_modified). The first value is the starting date (or datetime), +the second value is the ending date(or datetime). +NA's within the vector indicate a half-bound date. +For example, \code{time = c("2024-01-01", NA)} will return all data starting +at 2024-01-01. +\code{time = c(NA, "2024-01-01")} will return all data from the beginning of +the timeseries until 2024-01-01. +By default, time is assumed UTC, although time zone attributes +will be accommodated. As an example, setting \code{time = as.POSIXct(c("2021-01-01 12:00:00", +"2021-01-01 14:00"), tz = "America/New_York")} will request data that between +noon and 2pm eastern time on 2021-01-01. +All time values RETURNED from the service are UTC with the exception of +daily data, which returns time values in local dates. +} +\examples{ +\dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} + +\donttest{ +site <- "USGS-02238500" +pcode <- "00060" +dv_data_sf <- read_waterdata_latest_field(monitoring_location_id = site, + parameter_code = pcode) + +dv_data_last_modified <- read_waterdata_latest_field(monitoring_location_id = site, + parameter_code = pcode, + last_modified = "P7D") + +dv_data_trim <- read_waterdata_latest_field(monitoring_location_id = site, + parameter_code = pcode, + properties = c("monitoring_location_id", + "value", + "time")) + +dv_data <- read_waterdata_latest_field(monitoring_location_id = site, + parameter_code = pcode, + skipGeometry = TRUE) + +multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01491000", + "USGS-01645000"), + parameter_code = c("00060", "00010")) + +} +\dontshow{\}) # examplesIf} +} From 51792cff3eea534ded807be1439b76916a09f858 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 7 Jul 2026 14:52:45 -0500 Subject: [PATCH 10/11] First pass at latest_field --- R/read_waterdata_latest_field.R | 17 +++++------------ man/read_waterdata_latest_field.Rd | 18 +++++------------- man/read_wateruse.Rd | 2 +- tests/testthat/tests_userFriendly_fxns.R | 10 +++++++++- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/R/read_waterdata_latest_field.R b/R/read_waterdata_latest_field.R index eece4a905..46e179701 100644 --- a/R/read_waterdata_latest_field.R +++ b/R/read_waterdata_latest_field.R @@ -33,27 +33,20 @@ #' @examplesIf is_dataRetrieval_user() #' #' \donttest{ -#' site <- "USGS-02238500" -#' pcode <- "00060" -#' dv_data_sf <- read_waterdata_latest_field(monitoring_location_id = site, -#' parameter_code = pcode) +#' site <- "USGS-01435000" #' -#' dv_data_last_modified <- read_waterdata_latest_field(monitoring_location_id = site, -#' parameter_code = pcode, -#' last_modified = "P7D") +#' field_data_sf <- read_waterdata_latest_field(monitoring_location_id = site) #' #' dv_data_trim <- read_waterdata_latest_field(monitoring_location_id = site, -#' parameter_code = pcode, #' properties = c("monitoring_location_id", #' "value", #' "time")) #' -#' dv_data <- read_waterdata_latest_field(monitoring_location_id = site, -#' parameter_code = pcode, +#' field_data <- read_waterdata_latest_field(monitoring_location_id = site, #' skipGeometry = TRUE) #' -#' multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01491000", -#' "USGS-01645000")) +#' multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01435000", +#' "USGS-14202650")) #' #' } read_waterdata_latest_field <- function( diff --git a/man/read_waterdata_latest_field.Rd b/man/read_waterdata_latest_field.Rd index a05dc71e9..6abc209bb 100644 --- a/man/read_waterdata_latest_field.Rd +++ b/man/read_waterdata_latest_field.Rd @@ -144,28 +144,20 @@ daily data, which returns time values in local dates. \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ -site <- "USGS-02238500" -pcode <- "00060" -dv_data_sf <- read_waterdata_latest_field(monitoring_location_id = site, - parameter_code = pcode) +site <- "USGS-01435000" -dv_data_last_modified <- read_waterdata_latest_field(monitoring_location_id = site, - parameter_code = pcode, - last_modified = "P7D") +field_data_sf <- read_waterdata_latest_field(monitoring_location_id = site) dv_data_trim <- read_waterdata_latest_field(monitoring_location_id = site, - parameter_code = pcode, properties = c("monitoring_location_id", "value", "time")) -dv_data <- read_waterdata_latest_field(monitoring_location_id = site, - parameter_code = pcode, +field_data <- read_waterdata_latest_field(monitoring_location_id = site, skipGeometry = TRUE) -multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01491000", - "USGS-01645000"), - parameter_code = c("00060", "00010")) +multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01435000", + "USGS-14202650")) } \dontshow{\}) # examplesIf} diff --git a/man/read_wateruse.Rd b/man/read_wateruse.Rd index f475e0e5e..96affc46c 100644 --- a/man/read_wateruse.Rd +++ b/man/read_wateruse.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/read_waterdata_use.R +% Please edit documentation in R/read_wateruse.R \name{read_wateruse} \alias{read_wateruse} \title{Get USGS Water Use Data} diff --git a/tests/testthat/tests_userFriendly_fxns.R b/tests/testthat/tests_userFriendly_fxns.R index 1ba3d9853..0ec325d96 100644 --- a/tests/testthat/tests_userFriendly_fxns.R +++ b/tests/testthat/tests_userFriendly_fxns.R @@ -132,7 +132,15 @@ test_that("peak, rating curves, surface-water measurements", { # Surface meas: siteNumbers <- c("USGS-01594440", "USGS-040851325") - data <- read_waterdata_field_measurements(siteNumbers) + data <- read_waterdata_field_measurements( + monitoring_location_id = siteNumbers + ) + expect_is(data$monitoring_location_id, "character") + + # Latest Surface meas: + latest_data <- read_waterdata_latest_field( + monitoring_location_id = siteNumbers + ) expect_is(data$monitoring_location_id, "character") siteINFO_USGS <- read_waterdata_monitoring_location( From eb88086e54f0f7a59f73de8d54af9e0d45f7138c Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Wed, 8 Jul 2026 15:09:29 -0500 Subject: [PATCH 11/11] change name --- NAMESPACE | 2 +- R/read_waterdata_latest_field.R | 12 ++++++------ ... read_waterdata_latest_field_measurements.Rd} | 16 ++++++++-------- tests/testthat/tests_userFriendly_fxns.R | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) rename man/{read_waterdata_latest_field.Rd => read_waterdata_latest_field_measurements.Rd} (94%) diff --git a/NAMESPACE b/NAMESPACE index 5e6588bcc..58e18e703 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,7 +55,7 @@ export(read_waterdata_field_measurements) export(read_waterdata_field_meta) export(read_waterdata_latest_continuous) export(read_waterdata_latest_daily) -export(read_waterdata_latest_field) +export(read_waterdata_latest_field_measurements) export(read_waterdata_metadata) export(read_waterdata_monitoring_location) export(read_waterdata_parameter_codes) diff --git a/R/read_waterdata_latest_field.R b/R/read_waterdata_latest_field.R index 46e179701..f7a1dcf28 100644 --- a/R/read_waterdata_latest_field.R +++ b/R/read_waterdata_latest_field.R @@ -1,4 +1,4 @@ -#' Get Latest USGS field Data +#' Get latest USGS field measurement data #' #' @description `r get_description("latest-field-measurements")` #' @@ -35,21 +35,21 @@ #' \donttest{ #' site <- "USGS-01435000" #' -#' field_data_sf <- read_waterdata_latest_field(monitoring_location_id = site) +#' field_data_sf <- read_waterdata_latest_field_measurements(monitoring_location_id = site) #' -#' dv_data_trim <- read_waterdata_latest_field(monitoring_location_id = site, +#' dv_data_trim <- read_waterdata_latest_field_measurements(monitoring_location_id = site, #' properties = c("monitoring_location_id", #' "value", #' "time")) #' -#' field_data <- read_waterdata_latest_field(monitoring_location_id = site, +#' field_data <- read_waterdata_latest_field_measurements(monitoring_location_id = site, #' skipGeometry = TRUE) #' -#' multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01435000", +#' multi_site <- read_waterdata_latest_field_measurements(monitoring_location_id = c("USGS-01435000", #' "USGS-14202650")) #' #' } -read_waterdata_latest_field <- function( +read_waterdata_latest_field_measurements <- function( monitoring_location_id = NA_character_, parameter_code = NA_character_, statistic_id = NA_character_, diff --git a/man/read_waterdata_latest_field.Rd b/man/read_waterdata_latest_field_measurements.Rd similarity index 94% rename from man/read_waterdata_latest_field.Rd rename to man/read_waterdata_latest_field_measurements.Rd index 6abc209bb..3303acfe5 100644 --- a/man/read_waterdata_latest_field.Rd +++ b/man/read_waterdata_latest_field_measurements.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/read_waterdata_latest_field.R -\name{read_waterdata_latest_field} -\alias{read_waterdata_latest_field} -\title{Get Latest USGS field Data} +\name{read_waterdata_latest_field_measurements} +\alias{read_waterdata_latest_field_measurements} +\title{Get latest USGS field measurement data} \usage{ -read_waterdata_latest_field( +read_waterdata_latest_field_measurements( monitoring_location_id = NA_character_, parameter_code = NA_character_, statistic_id = NA_character_, @@ -146,17 +146,17 @@ daily data, which returns time values in local dates. \donttest{ site <- "USGS-01435000" -field_data_sf <- read_waterdata_latest_field(monitoring_location_id = site) +field_data_sf <- read_waterdata_latest_field_measurements(monitoring_location_id = site) -dv_data_trim <- read_waterdata_latest_field(monitoring_location_id = site, +dv_data_trim <- read_waterdata_latest_field_measurements(monitoring_location_id = site, properties = c("monitoring_location_id", "value", "time")) -field_data <- read_waterdata_latest_field(monitoring_location_id = site, +field_data <- read_waterdata_latest_field_measurements(monitoring_location_id = site, skipGeometry = TRUE) -multi_site <- read_waterdata_latest_field(monitoring_location_id = c("USGS-01435000", +multi_site <- read_waterdata_latest_field_measurements(monitoring_location_id = c("USGS-01435000", "USGS-14202650")) } diff --git a/tests/testthat/tests_userFriendly_fxns.R b/tests/testthat/tests_userFriendly_fxns.R index 0ec325d96..b59e8fbd9 100644 --- a/tests/testthat/tests_userFriendly_fxns.R +++ b/tests/testthat/tests_userFriendly_fxns.R @@ -138,7 +138,7 @@ test_that("peak, rating curves, surface-water measurements", { expect_is(data$monitoring_location_id, "character") # Latest Surface meas: - latest_data <- read_waterdata_latest_field( + latest_data <- read_waterdata_latest_field_measurements( monitoring_location_id = siteNumbers ) expect_is(data$monitoring_location_id, "character")