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

Moved to use regular importRDB in readNWISsites.

parent 8c014f51
No related branches found
No related tags found
1 merge request!39Overhaul of function names. Move some functionality to EGRET.
...@@ -88,7 +88,9 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE, ...@@ -88,7 +88,9 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
}) })
} else { } else {
doc <- obs_url doc <- obs_url
fileVecChar <- scan(obs_url, what = "", sep = "\n", quiet=TRUE)
pndIndx<-regexpr("^#", fileVecChar)
hdr <- fileVecChar[pndIndx > 0L]
} }
tmp <- read.delim( tmp <- read.delim(
......
...@@ -15,47 +15,6 @@ readNWISsite <- function(siteNumbers){ ...@@ -15,47 +15,6 @@ readNWISsite <- function(siteNumbers){
siteNumber <- paste(siteNumbers,collapse=",") siteNumber <- paste(siteNumbers,collapse=",")
urlSitefile <- paste("http://waterservices.usgs.gov/nwis/site/?format=rdb&siteOutput=Expanded&sites=",siteNumber,sep = "") urlSitefile <- paste("http://waterservices.usgs.gov/nwis/site/?format=rdb&siteOutput=Expanded&sites=",siteNumber,sep = "")
if(url.exists(urlSitefile)){ data <- importRDB1(urlSitefile,asDateTime=FALSE)
doc = tryCatch({
h <- basicHeaderGatherer()
doc <- getURL(urlSitefile, headerfunction = h$update)
}, warning = function(w) {
message(paste("URL caused a warning:", urlSitefile))
message(w)
}, error = function(e) {
message(paste("URL does not seem to exist:", urlSitefile))
message(e)
return(NA)
})
if(h$value()["Content-Type"] == "text/plain;charset=UTF-8"){
SiteFile <- read.delim(
textConnection(doc),
header = TRUE,
quote="\"",
dec=".",
sep='\t',
colClasses=c('character'),
fill = TRUE,
comment.char="#")
INFO <- SiteFile[-1,]
names(INFO) <- gsub("_",".",names(INFO))
INFO$queryTime <- Sys.time()
INFO$dec.lat.va <- as.numeric(INFO$dec.lat.va)
INFO$dec.long.va <- as.numeric(INFO$dec.long.va)
INFO$alt.va <- as.numeric(INFO$alt.va)
return(INFO)
} else {
message(paste("URL caused an error:", urlSitefile))
message("Content-Type=",h$value()["Content-Type"])
return(NA)
}
} else {
message("URL caused an error:", urlSitefile)
}
} }
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