Skip to content
Snippets Groups Projects
Commit c526d153 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Added same options to WQP sites function.

parent faeffcbf
No related branches found
No related tags found
1 merge request!63More error handling, specifically WQP.
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.1.0
Date: 2014-12-15
Version: 2.1.1
Date: 2015-01-02
Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "rhirsch@usgs.gov"),
person("Laura", "DeCicco", role = c("aut","cre"),
......
......@@ -59,13 +59,33 @@ whatWQPsites <- function(...){
matchReturn <- list(...)
options <- c("bBox","lat","long","within","countrycode","statecode","countycode","siteType","organization",
"siteid","huc","sampleMedia","characteristicType","characteristicName","pCode","activityId",
"startDateLo","startDateHi","mimeType","Zip","providers")
if(!all(names(matchReturn) %in% options)) warning(matchReturn[!(names(matchReturn) %in% options)],"is not a valid query parameter to the Water Quality Portal")
values <- sapply(matchReturn, function(x) URLencode(as.character(paste(eval(x),collapse="",sep=""))))
values <- sapply(matchReturn, function(x) URLencode(as.character(paste(eval(x),collapse=";",sep=""))))
values <- gsub(",","%2C",values)
values <- gsub("%20","+",values)
values <- gsub(":","%3A",values)
if("bBox" %in% names(values)){
values['bBox'] <- gsub(pattern = ";", replacement = ",", x = values['bBox'])
}
dateNames <- c("startDateLo","startDateHi","startDate","endDate")
if(any(names(values) %in% dateNames)){
index <- which(names(values) %in% dateNames)
# If a valid R date was put in, the format needs to be changed to mm-dd-yyyy for the WQP:
if(all(is.Date(as.Date(values[index])))){
dates <- as.Date(values[index])
dates <- format(as.Date(dates), format="%m-%d-%Y")
values[index] <- dates
} else if (!all(is.Date(as.Date(values[index],format="%m-%d-%Y")))){
warning("Please check the date format for the arguments: ", paste(names(values)[index], collapse=", "))
}
names(values)[names(values) == 'beginDate'] <- 'startDateLo'
names(values)[names(values) == 'endDate'] <- 'startDateHi'
}
urlCall <- paste(paste(names(values),values,sep="="),collapse="&")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment