Skip to content

Commit

Permalink
improve performance of discover nhdplus by calling geoserver directly…
Browse files Browse the repository at this point in the history
… for #417
  • Loading branch information
dblodgett-usgs committed Dec 17, 2024
1 parent 9267640 commit b517cfd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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", URLencode(URL))$content))

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

}, error = function(e) NULL)

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

0 comments on commit b517cfd

Please sign in to comment.