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
33f2ac46
Commit
33f2ac46
authored
Mar 02, 2017
by
David Watkins
Browse files
got the pattern?
parent
d928f477
Changes
3
Hide whitespace changes
Inline
Side-by-side
R/importNGWMN_wml2.R
View file @
33f2ac46
...
...
@@ -113,18 +113,24 @@ importNGWMN_wml2 <- function(input, asDateTime=FALSE, tz=""){
}
#' parse the timeseries portion of a waterML2 file
#' @param input XML with only the wml2:MeasurementTimeseries node and children
#'
#' Returns data frame columns of all information with each time series measurement;
#' Anything defined as a default, is returned as an attribute of that data frame.
#'
#' @param input XML with only the wml2:MeasurementTimeseries node and children
#' @importFrom xml2 xml_attr xml_find_all xml_text
#' @importFrom dplyr mutate
#' @importFrom lubridate parse_date_time
#' @export
parseWaterML2Timeseries
<-
function
(
input
,
asDateTime
)
{
gmlID
<-
xml_attr
(
input
,
"id"
)
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"
))
valueNodes
<-
xml_find_all
(
TVP
,
".//wml2:value"
)
values
<-
as.numeric
(
xml_text
(
valueNodes
))
nVals
<-
length
(
values
)
gmlID
<-
rep
(
gmlID
,
nVals
)
#
gmlID <- rep(gmlID, nVals)
#df of date, time, dateTime
oneCol
<-
rep
(
NA
,
nVals
)
...
...
@@ -148,10 +154,21 @@ parseWaterML2Timeseries <- function(input, asDateTime) {
}
uom
<-
xml_attr
(
valueNodes
,
"uom"
,
default
=
NA
)
source
<-
xml_attr
(
xml_find_all
(
TVP
,
".//wml2:source"
),
"title"
)
comment
<-
xml_text
(
xml_find_all
(
TVP
,
".//wml2:comment"
))
df
<-
cbind.data.frame
(
source
,
timeDF
,
value
=
values
,
uom
,
comment
,
gmlID
,
stringsAsFactors
=
FALSE
)
#TODO: other fields, then list, then df from list
tvpQuals
<-
xml_text
(
xml_find_all
(
TVP
,
".//swe:description"
))
defaultMeta
<-
xml_find_all
(
input
,
".//wml2:DefaultTVPMeasurementMetadata"
)
defaultQuals
<-
xml_text
(
xml_find_all
(
defaultMeta
,
".//swe:description"
))
defaultUOM
<-
xml_attr
(
xml_find_all
(
defaultMeta
,
".//wml2:uom"
),
"title"
,
default
=
NA
)
#attach defaultQuals as attributes
df_vars
<-
list
(
source
,
timeDF
,
value
=
values
,
uom
,
comment
)
df_use
<-
df_vars
[
sapply
(
df_vars
,
function
(
x
){
length
(
x
)
>
0
&&
!
all
(
is.na
(
x
))})]
df
<-
data.frame
(
df_use
,
stringsAsFactors
=
FALSE
)
attr
(
df
,
"defaultQualifier"
)
<-
defaultQuals
attr
(
df
,
"defaultUOM"
)
<-
defaultUOM
attr
(
df
,
"gmlID"
)
<-
gmlID
return
(
df
)
}
\ No newline at end of file
R/importWaterML2.r
View file @
33f2ac46
...
...
@@ -70,6 +70,10 @@ importWaterML2 <- function(obs_url, asDateTime=FALSE, tz="UTC"){
mergedDF
<-
NULL
for
(
t
in
timeSeries
){
df
<-
parseWaterML2Timeseries
(
t
,
asDateTime
)
#remove time and date columns
TVP
<-
xml_find_all
(
t
,
".//wml2:MeasurementTVP"
)
#time-value pairs
time
<-
xml_text
(
xml_find_all
(
TVP
,
".//wml2:time"
))
if
(
asDateTime
){
...
...
man/parseWaterML2Timeseries.Rd
0 → 100644
View file @
33f2ac46
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/importNGWMN_wml2.R
\name{parseWaterML2Timeseries}
\alias{parseWaterML2Timeseries}
\title{parse the timeseries portion of a waterML2 file}
\usage{
parseWaterML2Timeseries(input, asDateTime)
}
\arguments{
\item{input}{XML with only the wml2:MeasurementTimeseries node and children}
}
\description{
Returns data frame columns of all information with each time series measurement;
Anything defined as a default, is returned as an attribute of that data frame.
}
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