Closed lindsayplatt closed 2 years ago
The problem queries are coming back with a 400 error from the server. The message that comes back from the server is: "299 WQP \"The value of bBox=178.768914,51.398187,180.768914,53.398187 is not a valid bounding box.\"
The requirements for bbox in WQP are: "Western-most longitude, Southern-most latitude, Eastern-most longitude, and Northern-most longitude separated by commas,expressed in decimal degrees, WGS84, and longitudes west of Greenwich are negative. (Example: bBox=-92.8,44.2,-88.9,46.0)"
I'm guessing the problem is because the west-east coordinates cross 180. I tried fiddling with coordinates, like:
bbox_6120_neg <- c(xmin = 178.768914, ymin = 51.398187,
xmax = -179.2311, ymax = 53.398187)
but that gave the same error.
I'll get in touch with the WQP developers and see if there are additional restrictions on the WQP bbox argument.
I'll fiddle with our output so that the message from WQP gets displayed to the user. I think it will still need to be an error though - because that particular error will need to be displayed if a user inputs a wrong bbox as defined by the WQP. Right now the error message isn't displayed because it's assuming the same structure as what NWIS uses.
bbox_6120_neg <- c(xmin = -179.2311, ymin = 51.398187,
xmax = -178.768914, ymax = 53.398187)
works (flipping your min max for x
)
but I don't think that's the same (? maybe? IDK...) The coordinates we want are:
xmin = 178.768914
xmax = 180.768914
I think the 178 needs to stay positive, and the 180.768 should be changed to 180.768-360 = -179.2311.
What you have doesn't cross 180. But 🤷♀️ I would not be surprised to find I'm missing something?
Hmmmm the following returns data at
# Returns one site at 179.1987 long
bbox_5940_fix <-
c(xmin = 178.768914, ymin = 49.398187,
xmax = -(180.768914-360), ymax = 51.398187)
dataRetrieval::whatWQPdata(
sampleMedia = c("Water", "water"),
siteType = "Stream",
bBox = bbox_5940_fix
)
total_type lat lon ProviderName OrganizationIdentifier OrganizationFormalName
1 FeatureCollection Feature Point 51.39481 179.1987 NWIS USGS-AK USGS Alaska Water Science Center
MonitoringLocationIdentifier MonitoringLocationName MonitoringLocationTypeName ResolvedMonitoringLocationTypeName
1 USGS-512347179120570 STREAM (95-53) ON AMCHITKA IS AK Stream Stream
HUCEightDigitCode siteUrl activityCount resultCount
1 19030103 https://www.waterqualitydata.us/provider/NWIS/USGS-AK/USGS-512347179120570/ 1 38
StateName CountyName
1 Alaska Aleutians West Census Area
-(180.768914-360) is (positive) 179.2311... So that query is from 178 to 179, but you wanted 178 to 180.7. So, you got 1 site, but there might be more.
I think you want 180.768914-360 (so, -179.2311)
Am I correct in saying that it doesn't seem like the service supports 1) values that exceed 180 (or are below -180), 2) paired values that include one negative and one positive number?
So I'd say that Lindsay's original box still isn't supported (Laura is correct that it spans more than the one I mocked up and the one that Lindsay landed on, which is 178.768914 to 179.2311). But now we know this and you can set your boxes up to avoid this issue. One way to do that is to start them on the 180° mark (I'm assuming you are using sf::st_make_grid()
and can use offset
to do that?
Still think it is worth following up with WQP team to see if this is a little weird bug.
Correct, it appears the query can't cross 180. I've sent a message to ask the WQP devs to confirm, but that seems to be what we're seeing.
So yeah, splitting it into 2 should work.
~I don't think the offset
from sf::st_make_grid()
will matter because I would just run into the same issue on the other side since the grid cells are all the same size. Since I will have already captured anything >180 by the grid cells on the opposite side, I think I can just cut them off at 180.~ EDIT: Actually, it would work (see below, where grey is original, red is the shifted).
Sounds like the official WQP solution is to split it into 2 bounding boxes.
I will work to make the message from a 400 response more user friendly.
I'm closing this issue so I can distill the improve 400 message task to just what's needed to be done. We did learn from this issue that WQP doesn't want to cross the 180 meridian.
Describe the bug I am doing a big nationwide pull and am using grids across the USA + territories to organize the pull into chunks. I was able to run the pull for each of these grids without issue, except for two of them over in the Aleutian Islands. I imagine it is because there is not any data, but that is the case for some of the other grids over in those islands and they just return an empty df. Rather than the current error, I'd love if
dataRetrieval
could return either a more helpful error or just return an empty dataset.To Reproduce Steps to reproduce the behavior:
Expected behavior I would expect no data to be returned, not a failure.
Screenshots
The image below shows the two cells that are failing and how they spatially relate to the others.
I tested the cells around them and those don't fail (blue = no data but no fail, returned empty df; green = data available)
My environment after running the code above:
Console with error message:
Session Info Please include your session info:
Additional context I will code in a workaround for now with a
tryCatch()
, so I am not blocked by this behavior. I did also make sure that I have the most up-to-date version ofdataRetrieval
before logging this issue.