diff --git a/R/getNWISSites.R b/R/getNWISSites.R index 708a26db675d67c5e01280e3098d0c9a668aa807..fe7001f61a2877bb7ed813fb6c2518b9a2f6dbbf 100644 --- a/R/getNWISSites.R +++ b/R/getNWISSites.R @@ -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) diff --git a/R/getRDB1Data.r b/R/getRDB1Data.r index edf14e3aff4a6d822e245bc0b3b2ab5092a4ca56..c1a470edb85fd8b99557530efb4e1752c871ec55 100644 --- a/R/getRDB1Data.r +++ b/R/getRDB1Data.r @@ -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, diff --git a/R/getRawQWData.r b/R/getRawQWData.r index 09612a068a043ed6b77d043cb088fba57eb7d08f..7589cce5bc1bf3da6d47065dedfbff440ca23735 100644 --- a/R/getRawQWData.r +++ b/R/getRawQWData.r @@ -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) diff --git a/inst/doc/dataRetrieval.R b/inst/doc/dataRetrieval.R index 49ab3e8fdc3e7f2edfe7ece5a80d05bde400aa72..2ee4a6c27c24a6a6b14f3d5746c49ce75524d829 100644 --- a/inst/doc/dataRetrieval.R +++ b/inst/doc/dataRetrieval.R @@ -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,"]") )) diff --git a/inst/doc/dataRetrieval.Rnw b/inst/doc/dataRetrieval.Rnw index 5432158041474cfaeeb8debdda4edae8c4055160..ecd2d82431a11a2965d254b9fe479b5d9e42549e 100644 --- a/inst/doc/dataRetrieval.Rnw +++ b/inst/doc/dataRetrieval.Rnw @@ -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,"]") )) diff --git a/inst/doc/dataRetrieval.pdf b/inst/doc/dataRetrieval.pdf index ba94ac345fe83f8ae7795b7a9e8dfd23ffee34bf..27ce75a2fd0e1b256363d8337e20c6b207176bb7 100644 Binary files a/inst/doc/dataRetrieval.pdf and b/inst/doc/dataRetrieval.pdf differ diff --git a/man/getNWISSites.Rd b/man/getNWISSites.Rd index 0fb2734a0e1f1f01b978d617e063ca1e149d2f71..3921badfae3d4d49bb7973b0982b07203f1cbb7e 100644 --- a/man/getNWISSites.Rd +++ b/man/getNWISSites.Rd @@ -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") diff --git a/man/getWQPqwData.Rd b/man/getWQPqwData.Rd index 7c351b3b30cd248f11bbda405b216b583bf4509b..44c6244eef89d43b496826606cd61cf3dd215776 100644 --- a/man/getWQPqwData.Rd +++ b/man/getWQPqwData.Rd @@ -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}}, diff --git a/vignettes/dataRetrieval-concordance.tex b/vignettes/dataRetrieval-concordance.tex index 7fa17698e20d5c90bf79dfa462958e1408da497d..48e40e6aabc983953b36dfca326368e1d5896a70 100644 --- a/vignettes/dataRetrieval-concordance.tex +++ b/vignettes/dataRetrieval-concordance.tex @@ -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 % diff --git a/vignettes/figure/egretEx.pdf b/vignettes/figure/egretEx.pdf index 2b74285fd7de68e5a23b1cf2c98574b89877af36..b06cd6fa6226005c41c3dff6449a573b0f09a9d7 100644 Binary files a/vignettes/figure/egretEx.pdf and b/vignettes/figure/egretEx.pdf differ diff --git a/vignettes/figure/getNWIStemperaturePlot.pdf b/vignettes/figure/getNWIStemperaturePlot.pdf index 86c9793ba058f459ceafe2992c7f0ee5bdff6884..b89257452f8190556a4b65ee34493c5ea5f6f4b8 100644 Binary files a/vignettes/figure/getNWIStemperaturePlot.pdf and b/vignettes/figure/getNWIStemperaturePlot.pdf differ diff --git a/vignettes/figure/getQWtemperaturePlot.pdf b/vignettes/figure/getQWtemperaturePlot.pdf index 02c128eb0cc6bab168544d805540ab85651ab893..9a5f1629424ea4246c17101915a887bac0eed346 100644 Binary files a/vignettes/figure/getQWtemperaturePlot.pdf and b/vignettes/figure/getQWtemperaturePlot.pdf differ