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

Added state code lookup.

Fixes #102.
parent cca1b997
No related branches found
No related tags found
1 merge request!117More tz and state code updates.
......@@ -25,6 +25,7 @@ export(readWQPdata)
export(readWQPqw)
export(renameNWISColumns)
export(stateCd)
export(stateCdLookup)
export(whatNWISdata)
export(whatNWISsites)
export(whatWQPsites)
......
......@@ -101,6 +101,10 @@ readNWISdata <- function(service="dv", ...){
format <- "waterml,1.1"
baseURL <- "http://waterservices.usgs.gov/nwis/"
if("stateCd" %in% names(values)){
values["stateCd"] <- stateCdLookup(values["stateCd"], "postal")
}
if(service == "iv"){
baseURL <- "http://nwis.waterservices.usgs.gov/nwis/"
} else if (service == "qwdata"){
......@@ -199,7 +203,42 @@ readNWISdata <- function(service="dv", ...){
})
}
return(retval)
}
#' State code look up
#'
#' Function to simplify finding state and state code definitions. Used in \code{readNWISdata}
#' and \code{readWQPdata}.
#'
#' @param input could be character (full name, abbreviation, id), or numeric (id)
#' @param outputType character can be "postal","fullName","tableIndex", or "id".
#' @export
#' @examples
#' fullName <- stateCdLookup("wi", "fullName")
#' abbriev <- stateCdLookup("Wisconsin", "postal")
#' id <- stateCdLookup("WI", "id")
#' name <- stateCdLookup(55, "fullName")
#' index <- stateCdLookup("WI", "tableIndex")
#' stateCd[index,]
stateCdLookup <- function(input, outputType="postal"){
outputType <- match.arg(outputType, c("postal","fullName","tableIndex","id"))
if(is.numeric(input) | !is.na(suppressWarnings(as.numeric(input)))){
input <- which(input == as.numeric(stateCd$STATE))
} else if(nchar(input) == 2){
input <- which(tolower(input) == tolower(stateCd$STUSAB))
} else {
input <- which(tolower(input) == tolower(stateCd$STATE_NAME))
}
retVal <- switch(outputType,
postal = stateCd$STUSAB[input],
fullName = stateCd$STATE_NAME[input],
tableIndex = input,
id = stateCd$STATE[input]
)
return(retval)
return(retVal)
}
......@@ -35,6 +35,7 @@ Web service retrieval functions:
|`whatWQPsites` | `...` | WQP site search using user-specified queries |
* `Common 3` = siteNumber, startDate, endDate
* `...` = user-defined arguments.
##Reporting bugs
......
......@@ -4,7 +4,7 @@
\alias{readWQPqw}
\title{Raw Data Import for Water Quality Portal}
\usage{
readWQPqw(siteNumbers, parameterCd, startDate = "", endDate = "")
readWQPqw(siteNumbers, parameterCd, startDate = "", endDate = "", tz = "")
}
\arguments{
\item{siteNumbers}{character site number. This needs to include the full agency code prefix.}
......
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