diff --git a/NAMESPACE b/NAMESPACE index 7db39b0446d485d8c85d3fc366a0688ec9ba4ae2..77da01785211d1fb393f0539f098102e9d42f43a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(getDataAvailability) export(getDataFromFile) export(getGeneralWQPData) export(getMetaData) +export(getNWISSites) export(getParameterInfo) export(getQWDataFromFile) export(getRDB1Data) diff --git a/R/getNWISSites.R b/R/getNWISSites.R new file mode 100644 index 0000000000000000000000000000000000000000..78172d2c8e72bb81f7efe3da58cc0f3405b5bd54 --- /dev/null +++ b/R/getNWISSites.R @@ -0,0 +1,28 @@ +#' Site Data Import from NWIS +#' +#' Returns a list of sites from the NWIS web service. This function gets the data from: \url{http://waterservices.usgs.gov/rest/Site-Test-Tool.html}. +#' Arguments to the function should be based on \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} +#' +#' @param \dots see \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} for a complete list of options +#' @keywords data import NWIS web service +#' @return retval dataframe +#' @export +#' @examples +#' siteListPhos <- getNWISSites(stateCd="OH",parameterCd="00665") +getNWISSites <- function(...){ + + matchReturn <- match.call() + + values <- sapply(matchReturn[-1], function(x) URLencode(as.character(paste(x,collapse="",sep="")))) + + urlCall <- paste(paste(names(values),values,sep="="),collapse="&") + + + baseURL <- "http://waterservices.usgs.gov/nwis/site/?format=rdb&siteOutput=expanded&" + urlCall <- paste(baseURL, + urlCall,sep = "") + + retval <- getRDB1Data(urlCall) + + return(retval) +} diff --git a/R/getRDB1Data.r b/R/getRDB1Data.r index ded1fa2bd2e8b2fdaead39a3edfde6f0ca0d229d..2fe495e7326107c44d91c48f5460f0bf16e4b197 100644 --- a/R/getRDB1Data.r +++ b/R/getRDB1Data.r @@ -31,15 +31,19 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE){ dataType <- tmp[1,] data <- tmp[-1,] - if (asDateTime){ - data[,regexpr('d$', dataType) > 0] <- as.POSIXct(strptime(data[,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M")) - } else { - data[,regexpr('d$', dataType) > 0] <- as.Date(data[,regexpr('d$', dataType) > 0]) + if(sum(regexpr('d$', dataType) > 0) > 0){ + if (asDateTime){ + data[,regexpr('d$', dataType) > 0] <- as.POSIXct(strptime(data[,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M")) + } else { + data[,regexpr('d$', dataType) > 0] <- as.Date(data[,regexpr('d$', dataType) > 0]) + } } - tempDF <- data[,which(regexpr('n$', dataType) > 0)] - tempDF <- suppressWarnings(sapply(tempDF, function(x) as.numeric(x))) - data[,which(regexpr('n$', dataType) > 0)] <- tempDF + if (sum(regexpr('n$', dataType) > 0) > 0){ + tempDF <- data[,which(regexpr('n$', dataType) > 0)] + tempDF <- suppressWarnings(sapply(tempDF, function(x) as.numeric(x))) + data[,which(regexpr('n$', dataType) > 0)] <- tempDF + } row.names(data) <- NULL return(data) } diff --git a/man/getNWISSites.Rd b/man/getNWISSites.Rd new file mode 100644 index 0000000000000000000000000000000000000000..5426b117c8114dffb9cd25bd6cc76193510d60ab --- /dev/null +++ b/man/getNWISSites.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2 (4.0.1): do not edit by hand +\name{getNWISSites} +\alias{getNWISSites} +\title{Site Data Import from NWIS} +\usage{ +getNWISSites(...) +} +\arguments{ +\item{\dots}{see \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} for a complete list of options} +} +\value{ +retval dataframe +} +\description{ +Returns a list of sites from the NWIS web service. This function gets the data from: \url{http://waterservices.usgs.gov/rest/Site-Test-Tool.html}. +Arguments to the function should be based on \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} +} +\examples{ +siteListPhos <- getNWISSites(stateCd="OH",parameterCd="00665") +} +\keyword{NWIS} +\keyword{data} +\keyword{import} +\keyword{service} +\keyword{web} +