Skip to content

Commit

Permalink
eblondel#185 implement GMLEnvelope, GMLEnvelopeWithTimePeriod backwar…
Browse files Browse the repository at this point in the history
…d-compatibility for GML < 3
  • Loading branch information
eblondel committed Feb 14, 2022
1 parent 3350f2b commit f3bdb3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions R/GMLEnvelope.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ GMLEnvelope <- R6Class("GMLEnvelope",
super$decode(xml)
#backward compatibility in case of GML < 3
children <- xmlChildren(xml)
if(length(children) == 2 && names(children)[[1]]=="pos"){
self$lowerCorner <- t(as.matrix(as.numeric(unlist(strsplit(xmlValue(children[[1]]), " ")))))
self$upperCorner <- t(as.matrix(as.numeric(unlist(strsplit(xmlValue(children[[2]]), " ")))))
}
children <- children[names(children)=="pos"]
self$lowerCorner <- t(as.matrix(as.numeric(unlist(strsplit(xmlValue(children[[1]]), " ")))))
self$upperCorner <- t(as.matrix(as.numeric(unlist(strsplit(xmlValue(children[[2]]), " ")))))
}
)
)
10 changes: 10 additions & 0 deletions R/GMLEnvelopeWithTimePeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ GMLEnvelopeWithTimePeriod <- R6Class("GMLEnvelopeWithTimePeriod",
}
},

#decode
decode = function(xml){
super$decode(xml)
#backward compatibility in case of GML < 3
children <- xmlChildren(xml)
children <- children[names(children)=="timePosition"]
self$beginPosition <- as.POSIXct(strptime(unlist(strsplit(xmlValue(children[[1]]), " ")), "%Y-%m-%dT%H:%M:%S"), tz = "")
self$endPosition <- as.POSIXct(strptime(unlist(strsplit(xmlValue(children[[2]]), " ")), "%Y-%m-%dT%H:%M:%S"), tz = "")
},

#setBeginPosition
setBeginPosition = function(beginPosition){
if(!all(class(beginPosition)==c("POSIXct","POSIXt")) | is(beginPosition, "Date")){
Expand Down

0 comments on commit f3bdb3a

Please sign in to comment.