diff --git a/R/arcrest_tools.R b/R/arcrest_tools.R index 77389cc7..ef4e76ba 100644 --- a/R/arcrest_tools.R +++ b/R/arcrest_tools.R @@ -39,6 +39,8 @@ get_3dhp_service_info <- memoise::memoise(function() { #' Will default to the CRS of the input AOI if provided, and to 4326 for ID requests. #' @param buffer numeric. The amount (in meters) to buffer a POINT AOI by for an #' extended search. Default = 0.5 +#' @param page_size numeric default number of features to request at a time. Reducing +#' may help if 500 errors are experienced. #' @return a simple features (sf) object or valid types if no type supplied #' @keywords internal #' @importFrom sf st_crs st_geometry_type st_buffer st_transform st_zm read_sf st_bbox st_as_sfc @@ -48,7 +50,8 @@ get_3dhp_service_info <- memoise::memoise(function() { query_usgs_arcrest <- function(AOI = NULL, ids = NULL, type = NULL, where = NULL, t_srs = NULL, - buffer = 0.5){ + buffer = 0.5, + page_size = 2000){ si <- get_3dhp_service_info() @@ -141,7 +144,7 @@ query_usgs_arcrest <- function(AOI = NULL, ids = NULL, out <- NULL } else { - chunk_size <- 2000 + chunk_size <- page_size all_ids <- split(all_ids, ceiling(seq_along(all_ids)/chunk_size)) out <- rep(list(list()), length(all_ids)) diff --git a/R/get_hydro.R b/R/get_hydro.R index 18b9e418..255e614b 100644 --- a/R/get_hydro.R +++ b/R/get_hydro.R @@ -228,7 +228,8 @@ get_nwis <- function(AOI = NULL, t_srs = NULL, buffer = 20000){ #'} get_3dhp <- function(AOI = NULL, ids = NULL, type = NULL, universalreferenceid = NULL, - t_srs = NULL, buffer = 0.5) { + t_srs = NULL, buffer = 0.5, + page_size = 2000) { if(!is.null(universalreferenceid) & !grepl("outlet|reach|hydrolocation", type)) { stop("universalereferenceid can only be specified for hydrolocation features") @@ -247,7 +248,7 @@ get_3dhp <- function(AOI = NULL, ids = NULL, type = NULL, ids <- NULL } - query_usgs_arcrest(AOI, ids, type, where, t_srs, buffer) + query_usgs_arcrest(AOI, ids, type, where, t_srs, buffer, page_size) } diff --git a/R/get_oaproc.R b/R/get_oaproc.R index 8712c1ba..af8bd306 100644 --- a/R/get_oaproc.R +++ b/R/get_oaproc.R @@ -115,7 +115,10 @@ get_split_catchment <- function(point, upstream = TRUE) { url <- paste0(url_base, "nldi-splitcatchment/execution") - return(sf_post(url, make_json_input_split(point, upstream))) + return(sf_post(url, make_json_input_split(point, upstream), + err_mess = paste("Ensure that the point you submitted is within\n the", + "coterminous US and consider trying get_raindrop_trace\ to ensure", + "your point is not too close to a catchment boundary."))) } #' Get Cross Section From Point (experimental) @@ -330,7 +333,7 @@ get_xs <- function(url, fun, ...) { elevation_m = "elevation") } -sf_post <- function(url, json) { +sf_post <- function(url, json, err_mess = "") { tryCatch({ if(nhdplus_debug()) { @@ -349,7 +352,8 @@ sf_post <- function(url, json) { } }, error = function(e) { - message("Error calling processing service. \n Original error: \n", e) + message("Error calling processing service. \n Original error: \n", e, + "\n", err_mess) NULL }) } diff --git a/man/get_3dhp.Rd b/man/get_3dhp.Rd index 8548d437..2653e0fd 100644 --- a/man/get_3dhp.Rd +++ b/man/get_3dhp.Rd @@ -10,7 +10,8 @@ get_3dhp( type = NULL, universalreferenceid = NULL, t_srs = NULL, - buffer = 0.5 + buffer = 0.5, + page_size = 2000 ) } \arguments{ @@ -33,6 +34,9 @@ Will default to the CRS of the input AOI if provided, and to 4326 for ID request \item{buffer}{numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5} + +\item{page_size}{numeric default number of features to request at a time. Reducing +may help if 500 errors are experienced.} } \value{ a simple features (sf) object or valid types if no type supplied diff --git a/man/get_split_catchment.Rd b/man/get_split_catchment.Rd index bef14ebd..c1552d80 100644 --- a/man/get_split_catchment.Rd +++ b/man/get_split_catchment.Rd @@ -8,7 +8,7 @@ get_split_catchment(point, upstream = TRUE) } \arguments{ \item{point}{scf POINT including crs as created by: -\code{sf::st_sfc(sf::st_point(.. ,..), crs)}} +\code{sf::st_sfc(sf::st_point(.. ,..), crs)}.} \item{upstream}{logical If TRUE, the entire drainage basin upstream of the point provided is returned in addition to the local catchment.} @@ -18,9 +18,17 @@ sf data.frame containing the local catchment, the split portion and optionally the total drainage basin. } \description{ -Uses catchment splitting web service to retrieve +Uses a catchment splitting web service to retrieve the portion of a catchment upstream of the point provided. } +\details{ +This service works within the coterminous US NHDPlusV2 domain. If the point +provided falls on an NHDPlusV2 flowline as retrieved from \link{get_raindrop_trace} +the catchment will be split across the flow line. IF the point is not +along the flowline a small sub catchment will typically result. As a result, +most users of this function will want to use \link{get_raindrop_trace} prior +to calls to this function. +} \examples{ \donttest{ point <- sf::st_sfc(sf::st_point(x = c(-89.2158, 42.9561)), crs = 4326) diff --git a/man/query_usgs_arcrest.Rd b/man/query_usgs_arcrest.Rd index f8d26cc9..98d23004 100644 --- a/man/query_usgs_arcrest.Rd +++ b/man/query_usgs_arcrest.Rd @@ -10,7 +10,8 @@ query_usgs_arcrest( type = NULL, where = NULL, t_srs = NULL, - buffer = 0.5 + buffer = 0.5, + page_size = 2000 ) } \arguments{ @@ -33,6 +34,9 @@ Will default to the CRS of the input AOI if provided, and to 4326 for ID request \item{buffer}{numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5} + +\item{page_size}{numeric default number of features to request at a time. Reducing +may help if 500 errors are experienced.} } \value{ a simple features (sf) object or valid types if no type supplied diff --git a/tests/testthat/test_01_get_nldi.R b/tests/testthat/test_01_get_nldi.R index 54786a1c..d8cb5826 100644 --- a/tests/testthat/test_01_get_nldi.R +++ b/tests/testthat/test_01_get_nldi.R @@ -221,6 +221,11 @@ test_that("split", { expect_true(area[2] > units::set_units(900000000, "m^2")) + point <- sf::st_sfc(sf::st_point(c(-20.213274, 42.956989)), + crs = 4326) + + expect_message(get_split_catchment(point, upstream = TRUE), "Ensure that the point") + # Doesn't improve coverage # catchment2 <- get_split_catchment(snap_point, upstream = FALSE) #