Commit e8e6c19c authored by David Watkins's avatar David Watkins
Browse files

time zone change was broken

parent 6cf22fa4
......@@ -63,7 +63,7 @@ importNGWMN_wml2 <- function(input, asDateTime=FALSE, tz=""){
mergedDF <- NULL
for(t in timeSeries){
df <- parseWaterML2Timeseries(t, asDateTime)
df <- parseWaterML2Timeseries(t, asDateTime, tz)
if (is.null(mergedDF)){
mergedDF <- df
......@@ -122,7 +122,7 @@ importNGWMN_wml2 <- function(input, asDateTime=FALSE, tz=""){
#' @importFrom dplyr mutate
#' @importFrom lubridate parse_date_time
#' @export
parseWaterML2Timeseries <- function(input, asDateTime) {
parseWaterML2Timeseries <- function(input, asDateTime, tz) {
gmlID <- xml_attr(input,"id") #TODO: make this an attribute
TVP <- xml_find_all(input, ".//wml2:MeasurementTVP")#time-value pairs
rawTime <- xml_text(xml_find_all(TVP,".//wml2:time"))
......@@ -151,7 +151,7 @@ parseWaterML2Timeseries <- function(input, asDateTime) {
timeDF$dateTime <- parse_date_time(timeDF$dateTime, c("%Y","%Y-%m-%d","%Y-%m-%dT%H:%M","%Y-%m-%dT%H:%M:%S",
"%Y-%m-%dT%H:%M:%OS","%Y-%m-%dT%H:%M:%OS%z"), exact = TRUE)
#^^setting tz in as.POSIXct just sets the attribute, does not convert the time!
attr(time, 'tzone') <- tz
attr(timeDF$dateTime, 'tzone') <- tz
}
uom <- xml_attr(valueNodes, "uom", default = NA)
......
......@@ -71,7 +71,7 @@ importWaterML2 <- function(obs_url, asDateTime=FALSE, tz="UTC"){
for(t in timeSeries){
df <- parseWaterML2Timeseries(t, asDateTime)
df <- parseWaterML2Timeseries(t, asDateTime, tz)
#need to save attributes first, and create identifier column
saveAttribs <- attributes(df)[-(1:3)]
#remove time and date columns, add site col
......
......@@ -58,7 +58,7 @@ readNGWMNdata <- function(service, ..., asDateTime = TRUE, tz = ""){
featureID <- na.omit(gsub(":",".",dots[['featureID']]))
for(f in featureID){
obsFID <- retrieveObservation(featureID = f, asDateTime, attrs)
obsFID <- retrieveObservation(featureID = f, asDateTime, attrs, tz = tz)
obsFIDattr <- saveAttrs(attrs, obsFID)
obsFID <- removeAttrs(attrs, obsFID)
allObs <- bind_rows(allObs, obsFID)
......@@ -156,12 +156,12 @@ readNGWMNsites <- function(featureID){
}
retrieveObservation <- function(featureID, asDateTime, attrs){
retrieveObservation <- function(featureID, asDateTime, attrs, tz){
url <- drURL(base.name = "NGWMN", access = pkg.env$access, request = "GetObservation",
service = "SOS", version = "2.0.0", observedProperty = "urn:ogc:def:property:OGC:GroundWaterLevel",
responseFormat = "text/xml", featureOfInterest = paste("VW_GWDP_GEOSERVER", featureID, sep = "."))
returnData <- importNGWMN_wml2(url, asDateTime)
returnData <- importNGWMN_wml2(url, asDateTime, tz = tz)
if(nrow(returnData) == 0){
#need to add NA attributes, so they aren't messed up when stored as DFs
attr(returnData, "gml:identifier") <- NA
......
......@@ -4,7 +4,7 @@
\alias{parseWaterML2Timeseries}
\title{parse the timeseries portion of a waterML2 file}
\usage{
parseWaterML2Timeseries(input, asDateTime)
parseWaterML2Timeseries(input, asDateTime, tz)
}
\arguments{
\item{input}{XML with only the wml2:MeasurementTimeseries node and children}
......
......@@ -7,6 +7,8 @@
readNGWMNdata(service, ..., asDateTime = TRUE, tz = "")
}
\arguments{
\item{service}{char Service for the request - "observation" and "featureOfInterest" are implemented.}
\item{\dots}{Other parameters to supply, namely \code{featureID} or \code{bbox}}
\item{asDateTime}{logical if \code{TRUE}, will convert times to POSIXct format. Currently defaults to
......@@ -14,8 +16,7 @@ readNGWMNdata(service, ..., asDateTime = TRUE, tz = "")
\item{tz}{character to set timezone attribute of datetime. Default is an empty quote, which converts the
datetimes to UTC (properly accounting for daylight savings times based on the data's provided time zone offset).
Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"}
Accepts all values from \code{OlsonNames()}.}
}
\description{
Only water level data and site locations and names are currently available through the web service.
......@@ -42,6 +43,9 @@ noDataSite <- readNGWMNdata(featureID = noDataSite, service = "observation")
#bounding box
bboxSites <- readNGWMNdata(service = "featureOfInterest", bbox = c(30, -99, 31, 102))
#retrieve 100 sites. Set asDateTime to false since one site has an invalid date
bboxData <- readNGWMNdata(service = "observation", featureID = bboxSites$site[1:100],
asDateTime = FALSE)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment