Skip to content

Commit

Permalink
Merge pull request #10 from dblodgett-usgs/main
Browse files Browse the repository at this point in the history
labs.waterdata to api.water for NLDI
  • Loading branch information
joshualerickson authored Dec 17, 2024
2 parents 3795013 + 11208e0 commit b2a13fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ get_NLDI <- function(point){

comid <- nhdplusTools::discover_nhdplus_id(point)

nldiURLs <- list(basin_boundary = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/basin"),
UT = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=999"),
UM = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/navigation/UM/flowlines?distance=999"))
nldiURLs <- list(basin_boundary = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/basin"),
UT = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=999"),
UM = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/navigation/UM/flowlines?distance=999"))

nldi_data <- list()

Expand Down Expand Up @@ -49,9 +49,9 @@ get_NLDI_catchments <- function(point, type = 'local', method = 'all'){
if(is.na(comid)){stop('COMID not found')}

if(method == 'all'){
nldiURLs <- list(UT = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=999"))
nldiURLs <- list(UT = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=999"))
} else if (method == 'local'){
nldiURLs <- list(UT = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=0"))
nldiURLs <- list(UT = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=0"))
}

nldi_data <- list()
Expand Down Expand Up @@ -162,7 +162,7 @@ nldi_basin_function <- function(point){
clat <- point$geometry[[1]][[2]]
clng <- point$geometry[[1]][[1]]
rowid <- point$rowid
ids <- paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/position?coords=POINT%28",
ids <- paste0("https://api.water.usgs.gov/nldi/linked-data/comid/position?coords=POINT%28",
clng,"%20", clat, "%29")

error_ids <- httr::GET(url = ids,
Expand All @@ -172,7 +172,7 @@ nldi_basin_function <- function(point){
nld <- jsonlite::fromJSON(file.path(tempdir(),"nld_tmp.json"))


nldiURLs <- paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",nld$features$properties$identifier,"/basin")
nldiURLs <- paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",nld$features$properties$identifier,"/basin")

nldi_data <- sf::read_sf(nldiURLs)

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-nldi.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ test_that("testing upstream main and tribs from nhdplusTools", {

comid <- nhdplusTools::discover_nhdplus_id(point)

nldiURLs <- list(site_data = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/position?coords=POINT%28",
nldiURLs <- list(site_data = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/position?coords=POINT%28",
point[1,1]$geometry[[1]][1],"%20", point[1,1]$geometry[[1]][2], "%29"),
basin_boundary = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/basin"),
UT = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=999"),
UM = paste0("https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/",comid,"/navigation/UM/flowlines?distance=999"))
basin_boundary = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/basin"),
UT = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/navigation/UT/flowlines?distance=999"),
UM = paste0("https://api.water.usgs.gov/nldi/linked-data/comid/",comid,"/navigation/UM/flowlines?distance=999"))

nldi_data <- list()

Expand Down

0 comments on commit b2a13fe

Please sign in to comment.