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

Added a check for multi-sites.

parent e86721f5
No related branches found
No related tags found
1 merge request!11Added generalized NWIS data function, and functionality to WQP raw pulls (datetimes).
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#' multiData <- getRDB1Data(urlMulti) #' multiData <- getRDB1Data(urlMulti)
#' unitDataURL <- constructNWISURL(siteNumber,property, #' unitDataURL <- constructNWISURL(siteNumber,property,
#' as.character(Sys.Date()),as.character(Sys.Date()),'uv',format='tsv') #' as.character(Sys.Date()),as.character(Sys.Date()),'uv',format='tsv')
#' unitData <- getRDB1Data(unitDataURL, asDateT=TRUE) #' unitData <- getRDB1Data(unitDataURL, asDateTime=TRUE)
#' mulitSites <- getRDB1Data("http://waterservices.usgs.gov/nwis/dv/?format=rdb&stateCd=OH&parameterCd=00010")
getRDB1Data <- function(obs_url,asDateTime=FALSE){ getRDB1Data <- function(obs_url,asDateTime=FALSE){
retval = tryCatch({ retval = tryCatch({
...@@ -52,6 +53,16 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE){ ...@@ -52,6 +53,16 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE){
dataType <- tmp[1,] dataType <- tmp[1,]
data <- tmp[-1,] data <- tmp[-1,]
multiSiteCorrections <- -which(as.logical(apply(data[,1:2], 1, FUN=function(x) all(x %in% as.character(dataType[,1:2])))))
if(length(multiSiteCorrections) > 0){
data <- data[multiSiteCorrections,]
findRowsWithHeaderInfo <- as.integer(apply(data[,1:2], 1, FUN = function(x) if(x[1] == names(data)[1] & x[2] == names(data)[2]) 1 else 0))
findRowsWithHeaderInfo <- which(findRowsWithHeaderInfo == 0)
data <- data[findRowsWithHeaderInfo,]
}
if(sum(regexpr('d$', dataType) > 0) > 0){ if(sum(regexpr('d$', dataType) > 0) > 0){
if (asDateTime){ if (asDateTime){
...@@ -63,7 +74,7 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE){ ...@@ -63,7 +74,7 @@ getRDB1Data <- function(obs_url,asDateTime=FALSE){
if(length(unique(timeZone)) == 1){ if(length(unique(timeZone)) == 1){
data[,regexpr('d$', dataType) > 0] <- as.POSIXct(data[,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M", tz = unique(timeZone)) data[,regexpr('d$', dataType) > 0] <- as.POSIXct(data[,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M", tz = unique(timeZone))
} else { } else {
warning("Mixed time zone information") # warning("Mixed time zone information")
for(i in seq_along(row.names(data))){ for(i in seq_along(row.names(data))){
data[i,regexpr('d$', dataType) > 0] <- as.POSIXct(data[i,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M", tz = timeZone[i]) data[i,regexpr('d$', dataType) > 0] <- as.POSIXct(data[i,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M", tz = timeZone[i])
} }
......
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