Skip to content

Commit

Permalink
Merge pull request #418 from DOI-USGS/api-update
Browse files Browse the repository at this point in the history
Api update
  • Loading branch information
dblodgett-usgs authored Dec 17, 2024
2 parents 9f612b1 + f05320f commit abb1ec8
Show file tree
Hide file tree
Showing 139 changed files with 1,716 additions and 2,743 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Imports: hydroloom, dataRetrieval, dplyr, sf, units, magrittr, jsonlite, httr, x
Suggests: testthat, knitr, rmarkdown, ggmap, ggplot2, lwgeom, gifski, leaflet, httptest, future, future.apply
License: CC0
Encoding: UTF-8
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
VignetteBuilder: knitr
Config/testthat/parallel: true
Config/testthat/edition: 3
Expand Down
12 changes: 9 additions & 3 deletions R/A_nhdplusTools.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ nhdplus_attributes <- list(

assign("nhdplus_attributes", nhdplus_attributes, envir = nhdplusTools_env)

assign("geoserver_root", "https://labs.waterdata.usgs.gov/geoserver/",
assign("geoserver_root", "https://api.water.usgs.gov/geoserver/",
envir = nhdplusTools_env)

assign("arcrest_root", "https://hydro.nationalmap.gov/arcgis/rest/services/",
Expand Down Expand Up @@ -276,10 +276,16 @@ nhdplus_debug <- function() {
#' @noRd
get_nldi_url <- function() {

tier <- get("nldi_tier", envir = nhdplusTools_env)
tier_env <- Sys.getenv("NLDI_TIER")

tier <- if(tier_env != "") {
tier_env
} else {
get("nldi_tier", envir = nhdplusTools_env)
}

if (tier == "prod") {
"https://labs.waterdata.usgs.gov/api/nldi"
"https://api.water.usgs.gov/nldi"
} else if (tier == "test") {
"https://labs-beta.waterdata.usgs.gov/api/nldi"
} else {
Expand Down
15 changes: 13 additions & 2 deletions R/discover_nhdplus.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ discover_nhdplus_id <- function(point = NULL, nldi_feature = NULL, raindrop = FA
coords = sf::st_coordinates(point)

comid <- tryCatch({
as.integer(dataRetrieval::findNLDI(location = c(X = coords[1],
Y = coords[2]))$origin$identifier)

URL <- paste0(get("geoserver_root", envir = nhdplusTools_env),
"wmadata",
"/ows",
"?service=WFS&request=GetFeature&version=1.0.0", # axis order switched in 1.1.0
"&typeName=catchmentsp&outputFormat=application/json",
"&CQL_FILTER=INTERSECTS(the_geom, POINT (",
coords[1], " ", coords[2], "))",
"&propertyName=featureid")

d <- jsonlite::fromJSON(rawToChar(RETRY("GET", utils::URLencode(URL))$content))

as.integer(d$features$properties$featureid)

}, error = function(e) NULL)

Expand Down
2 changes: 1 addition & 1 deletion R/geoserver_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ query_usgs_geoserver <- function(AOI = NULL, ids = NULL,
version="1.1.0" outputFormat="application/json"',
' xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">',
'<wfs:Query xmlns:feature="https://cida.usgs.gov/',
'<wfs:Query xmlns:feature="https://api.water.usgs.gov/',
here$server,
'" typeName="feature:',
here$geoserver,
Expand Down
2 changes: 1 addition & 1 deletion R/get_hydro.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' See <doi:10.5066/P92U7ZUT> for full source data.
#'
#' See https://labs.waterdata.usgs.gov/geoserver/web/ for the web service.
#' See https://api.water.usgs.gov/geoserver/web/ for the web service.
#'
#' `huc12_nhdplusv2` derives from a snapshot of the WBD available from the nhdplusv2.
#' See \link{download_nhdplusv2} for source data documentation.
Expand Down
2 changes: 1 addition & 1 deletion R/get_nldi.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ query_nldi <- function(query, base_path = "/linked-data", parse_json = TRUE, err
message(url)
}

req_data <- rawToChar(httr::RETRY("GET", url)$content)
req_data <- rawToChar(httr::RETRY("GET", utils::URLencode(url))$content)

if (nchar(req_data) == 0) {
NULL
Expand Down
14 changes: 7 additions & 7 deletions docs/404.html

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

14 changes: 7 additions & 7 deletions docs/DISCLAIMER.html

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

14 changes: 7 additions & 7 deletions docs/LICENSE.html

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

Loading

0 comments on commit abb1ec8

Please sign in to comment.