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

Made this function the old getGeneralWQPData function.

parent 63bd1ac4
No related branches found
No related tags found
1 merge request!15Fixed some bugs, changed getGeneralWQPData to getWQPData
#' Data Import from Water Quality Portal #' General Data Import from Water Quality Portal
#' #'
#' Imports data from Water Quality Portal web service. This function gets the data from: \url{http://www.waterqualitydata.us}. This function is more general than getQWData #' Imports data from Water Quality Portal web service. This function gets the data from here: \url{http://www.waterqualitydata.us}.
#' because it allows for other agencies rather than the USGS. Therefore, the 5-digit parameter code cannot be used. #' because it allows for other agencies rather than the USGS.
#' Instead, this function uses characteristicName. A complete list can be found here
#' #'
#' @param siteNumber string site number. If USGS, it should be in the form :'USGS-XXXXXXXXX...' #' @param \dots see \url{www.waterqualitydata.us/webservices_documentation.jsp} for a complete list of options
#' @param characteristicName string
#' @param startDate string starting date for data retrieval in the form YYYY-MM-DD.
#' @param endDate string ending date for data retrieval in the form YYYY-MM-DD.
#' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks.
#' @keywords data import WQP web service #' @keywords data import WQP web service
#' @return retval dataframe with first column dateTime, and at least one qualifier and value columns #' @return retval dataframe with first column dateTime, and at least one qualifier and value columns
#' (subsequent qualifier/value columns could follow depending on requested parameter codes) #' (subsequent qualifier/value columns could follow depending on requested parameter codes)
#' @export #' @export
#' @import RCurl
#' @examples #' @examples
#' # These examples require an internet connection to run #' nameToUse <- "pH"
#' Chloride <- getWQPData('USGS-01594440','Chloride', '', '') #' pHData <- getWQPData(siteid="USGS-04024315",characteristicName=nameToUse)
#' SC <- getWQPData('WIDNR_WQX-10032762','Specific conductance', '', '') getWQPData <- function(...){
#' NWIS_Cl <- getWQPData('USGS-04024000','30234', '', '')
#' MultipleQW <- getWQPData('USGS-04024000',c('30234','90095'), '', '') matchReturn <- match.call()
getWQPData <- function(siteNumber,characteristicName,startDate,endDate,interactive=TRUE){
options <- c("bBox","lat","long","within","countrycode","statecode","countycode","siteType","organization",
retval <- retrieveWQPqwData(siteNumber=siteNumber, "siteid","huc","sampleMedia","characteristicType","characteristicName","pCode","activityId",
parameterCd=characteristicName, "startDateLo","startDateHi","mimeType","Zip","providers")
startDate=startDate,
endDate=endDate, if(!all(names(matchReturn[-1]) %in% options)) warning(matchReturn[!(names(matchReturn[-1]) %in% options)],"is not a valid query parameter to the Water Quality Portal")
interactive=interactive)
#Check for pcode: values <- sapply(matchReturn[-1], function(x) URLencode(as.character(paste(eval(x),collapse="",sep=""))))
if(all(nchar(characteristicName) == 5)){
suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(characteristicName))))
} else {
pCodeLogic <- FALSE
}
if(nrow(retval) > 0){
data <- processQWData(retval,pCodeLogic)
} else {
data <- NULL
}
return(data) values <- gsub(",","%2C",values)
values <- gsub("%20","+",values)
urlCall <- paste(paste(names(values),values,sep="="),collapse="&")
baseURL <- "http://www.waterqualitydata.us/Result/search?"
urlCall <- paste(baseURL,
urlCall,
"&mimeType=tsv",sep = "")
retVal <- basicWQPData(urlCall)
return(retVal)
} }
\ No newline at end of file
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