Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Water
dataRetrieval
Commits
e8e6c19c
Commit
e8e6c19c
authored
Mar 07, 2017
by
David Watkins
Browse files
time zone change was broken
parent
6cf22fa4
Changes
5
Hide whitespace changes
Inline
Side-by-side
R/importNGWMN_wml2.R
View file @
e8e6c19c
...
...
@@ -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
(
time
DF
$
dateTime
,
'tzone'
)
<-
tz
}
uom
<-
xml_attr
(
valueNodes
,
"uom"
,
default
=
NA
)
...
...
R/importWaterML2.r
View file @
e8e6c19c
...
...
@@ -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
...
...
R/readNGWMNdata.R
View file @
e8e6c19c
...
...
@@ -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
...
...
man/parseWaterML2Timeseries.Rd
View file @
e8e6c19c
...
...
@@ -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}
...
...
man/readNGWMNdata.Rd
View file @
e8e6c19c
...
...
@@ -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)
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment