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

Merge pull request #24 from ldecicco-USGS/master

Fixed bug, cleaned up help files.
parents ad7317a6 fc9b3769
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,13 @@
#'
#' 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}
#' Mapper format is used
#'
#' @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
#' @return retval dataframe with agency_cd, site_no, station_nm, site_tp_cd, dec_lat_va, and dec_long_va.
#' @export
#' @import XML
#' @examples
#' siteListPhos <- getNWISSites(stateCd="OH",parameterCd="00665")
getNWISSites <- function(...){
......@@ -18,20 +20,53 @@ getNWISSites <- function(...){
urlCall <- paste(paste(names(values),values,sep="="),collapse="&")
baseURL <- "http://waterservices.usgs.gov/nwis/site/?format=rdb&"
baseURL <- "http://waterservices.usgs.gov/nwis/site/?format=mapper&"
urlCall <- paste(baseURL,
urlCall,sep = "")
retval <- getRDB1Data(urlCall)
if("dec_lat_va" %in% names(retval)){
retval$dec_lat_va <- as.numeric(retval$dec_lat_va)
}
if("dec_long_va" %in% names(retval)){
retval$dec_long_va <- as.numeric(retval$dec_long_va)
h <- basicHeaderGatherer()
doc = tryCatch({
returnedDoc <- getURI(urlCall, headerfunction = h$update)
if(h$value()["Content-Type"] == "text/xml;charset=UTF-8"){
xmlTreeParse(returnedDoc, getDTD = FALSE, useInternalNodes = TRUE)
} else {
message(paste("URL caused an error:", obs_url))
message("Content-Type=",h$value()["Content-Type"])
return(NA)
}
}, warning = function(w) {
message(paste("URL caused a warning:", obs_url))
message(w)
}, error = function(e) {
message(paste("URL does not seem to exist:", obs_url))
message(e)
return(NA)
})
doc <- xmlRoot(doc)
numChunks <- xmlSize(doc)
for(i in 1:numChunks){
chunk <- doc[[1]]
site_no <- as.character(xpathApply(chunk, "site/@sno"))
station_nm <- as.character(xpathApply(chunk, "site/@sna"))
site_tp_cd <- as.character(xpathApply(chunk, "site/@cat"))
dec_lat_va <- as.numeric(xpathApply(chunk, "site/@lat"))
dec_long_va <- as.numeric(xpathApply(chunk, "site/@lng"))
agency_cd <- as.character(xpathApply(chunk, "site/@agc"))
df <- data.frame(agency_cd, site_no, station_nm, site_tp_cd,
dec_lat_va, dec_long_va, stringsAsFactors=FALSE)
if(1==i){
retval <- df
} else {
retval <- rbind(retval, df)
}
}
retval <- retval[!duplicated(retval),]
retval$queryTime <- Sys.time()
return(retval)
......
......@@ -40,6 +40,8 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE, qw=FALSE){
if(as.character(h$value()["Content-Type"]) == "text/plain;charset=UTF-8" | as.character(h$value()["Content-Type"]) == "text/plain"){
# comments <- readLines(doc)
tmp <- read.delim(
textConnection(doc),
header = TRUE,
......
......@@ -22,10 +22,8 @@
#' \code{\link{getSTORETSampleData}}, \code{\link{getNWISqwData}}, and \code{\link{readWQPData}}
#' @examples
#' # These examples require an internet connection to run
#' rawSample <- getWQPqwData('USGS-01594440','01075', '1985-01-01', '1985-03-31')
#' rawSampleAll <- getWQPqwData('USGS-05114000','', '1985-01-01', '1985-03-31')
#' rawSampleSelect <- getWQPqwData('USGS-05114000',c('00915','00931'), '1985-01-01', '1985-04-30')
#' rawStoret <- getWQPqwData('WIDNR_WQX-10032762','Specific conductance', '', '')
#' rawPcode <- getWQPqwData('USGS-01594440','01075', '1985-01-01', '1985-03-31')
#' rawCharacteristicName <- getWQPqwData('WIDNR_WQX-10032762','Specific conductance', '', '')
getWQPqwData <- function(siteNumber,parameterCd,startDate,endDate,interactive=TRUE){
url <- constructNWISURL(siteNumber,parameterCd,startDate,endDate,"wqp",interactive=interactive)
......
......@@ -210,7 +210,7 @@ names(dissolvedNitrate)
## ----getQWtemperaturePlot, echo=TRUE, fig.cap=paste(parameterINFO$parameter_nm, "at", siteINFO$station.nm[1])----
with(dissolvedNitrate, plot(
dateTime, result_va_00618,
startDateTime, result_va_00618,
xlab="Date",ylab = paste(parameterINFO$srsname,
"[",parameterINFO$parameter_units,"]")
))
......
......@@ -512,7 +512,7 @@ names(dissolvedNitrate)
<<getQWtemperaturePlot, echo=TRUE, fig.cap=paste(parameterINFO$parameter_nm, "at", siteINFO$station.nm[1])>>=
with(dissolvedNitrate, plot(
dateTime, result_va_00618,
startDateTime, result_va_00618,
xlab="Date",ylab = paste(parameterINFO$srsname,
"[",parameterINFO$parameter_units,"]")
))
......
No preview for this file type
......@@ -9,11 +9,12 @@ getNWISSites(...)
\item{\dots}{see \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} for a complete list of options}
}
\value{
retval dataframe
retval dataframe with agency_cd, site_no, station_nm, site_tp_cd, dec_lat_va, and dec_long_va.
}
\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}
Mapper format is used
}
\examples{
siteListPhos <- getNWISSites(stateCd="OH",parameterCd="00665")
......
......@@ -31,10 +31,8 @@ site name, such as 'USGS-01234567'.
}
\examples{
# These examples require an internet connection to run
rawSample <- getWQPqwData('USGS-01594440','01075', '1985-01-01', '1985-03-31')
rawSampleAll <- getWQPqwData('USGS-05114000','', '1985-01-01', '1985-03-31')
rawSampleSelect <- getWQPqwData('USGS-05114000',c('00915','00931'), '1985-01-01', '1985-04-30')
rawStoret <- getWQPqwData('WIDNR_WQX-10032762','Specific conductance', '', '')
rawPcode <- getWQPqwData('USGS-01594440','01075', '1985-01-01', '1985-03-31')
rawCharacteristicName <- getWQPqwData('WIDNR_WQX-10032762','Specific conductance', '', '')
}
\seealso{
\code{\link{getWQPData}}, \code{\link{getWQPSites}},
......
......@@ -2,7 +2,7 @@
1 127 1 49 0 1 7 15 1 1 14 55 1 3 0 36 1 2 0 8 1 9 0 %
24 1 3 0 21 1 4 0 6 1 8 0 18 1 3 0 25 1 1 4 19 1 9 0 %
6 1 7 0 22 1 8 0 16 1 2 0 11 1 23 0 22 1 9 0 20 1 3 0 %
6 1 17 0 28 1 12 0 10 1 9 0 20 1 4 0 14 1 4 0 33 1 17 %
6 1 17 0 28 1 39 0 10 1 9 0 20 1 4 0 14 1 4 0 33 1 13 %
0 39 1 14 0 18 1 2 0 14 1 2 0 49 1 4 0 7 1 4 0 11 1 2 %
0 17 1 7 0 22 1 8 0 21 1 4 0 9 1 4 0 79 1 1 2 9 1 1 4 %
4 1 20 0 44 1 4 0 30 1 4 0 22 1 4 0 21 1 26 0 13 1 9 %
......
No preview for this file type
No preview for this file type
No preview for this file type
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