Skip to content

Commit

Permalink
#57 GMLTemporalCRS, GMLCompoundCRS
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Sep 12, 2018
1 parent b055e75 commit 299c6aa
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(GMLAbstractTimePrimitive)
export(GMLAffineCS)
export(GMLBaseUnit)
export(GMLCartesianCS)
export(GMLCompoundCRS)
export(GMLConventionalUnit)
export(GMLConversion)
export(GMLCoordinateSystemAxis)
Expand Down Expand Up @@ -69,6 +70,7 @@ export(GMLReferenceableGridByArray)
export(GMLReferenceableGridByTransformation)
export(GMLReferenceableGridByVectors)
export(GMLSphericalCS)
export(GMLTemporalCRS)
export(GMLTemporalCS)
export(GMLTimeCS)
export(GMLTimePeriod)
Expand Down
65 changes: 65 additions & 0 deletions R/GMLCompoundCRS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' GMLCompoundCRS
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO GML compound CRS
#' @return Object of \code{\link{R6Class}} for modelling an GMLCompoundCRS
#' @format \code{\link{R6Class}} object.
#'
#' @field componentReferenceSystem
#'
#' @section Methods:
#' \describe{
#' \item{\code{new(xml, defaults, id)}}{
#' This method is used to instantiate a GML Abstract CRS
#' }
#' \item{\code{addComponentReferenceSystem(referenceSystem)}}{
#' Adds a reference system
#' }
#' \item{\code{delComponentReferenceSystem(referenceSystem)}}{
#' Deletes a reference system
#' }
#' }
#'
#' @references
#' ISO 19136:2007 Geographic Information -- Geographic Markup Language.
#' http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554
#'
#' OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
GMLCompoundCRS <- R6Class("GMLCompoundCRS",
inherit = GMLAbstractCRS,
private = list(
xmlElement = "CompoundCRS",
xmlNamespacePrefix = "GML"
),
public = list(

#+ componentReferenceSystem [2..*]: instance of AbstractSingleCRS
componentReferenceSystem = list(),

initialize = function(xml = NULL, defaults = list(), id = NULL){
super$initialize(xml = xml, defaults = defaults, id = id)
},

#addComponentReferenceSystem
addComponentReferenceSystem = function(referenceSystem){
if(!inherits(referenceSystem, "GMLAbstractSingleCRS")){
stop("The argument should be a instance of class CRS")
}
return(self$addListElement("componentReferenceSystem", referenceSystem))
},

#delComponentReferenceSystem
delComponentReferenceSystem = function(referenceSystem){
if(!inherits(referenceSystem, "GMLAbstractSingleCRS")){
stop("The argument should be a instance of class CRS")
}
return(self$delListElement("componentReferenceSystem", referenceSystem))
}

)
)
56 changes: 56 additions & 0 deletions R/GMLTemporalCRS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#' GMLTemporalCRS
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO GML temporal crs
#' @return Object of \code{\link{R6Class}} for modelling an GMLTemporalCRS
#' @format \code{\link{R6Class}} object.
#'
#' @field timeCS
#' @field temporalDatum
#'
#' @section Methods:
#' \describe{
#' \item{\code{new(xml, defaults, id)}}{
#' This method is used to instantiate a GML temporal CRS
#' }
#' }
#'
#' @references
#' ISO 19136:2007 Geographic Information -- Geographic Markup Language.
#' http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554
#'
#' OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
GMLTemporalCRS <- R6Class("GMLTemporalCRS",
inherit = GMLAbstractSingleCRS,
private = list(
xmlElement = "TemporalCRS",
xmlNamespacePrefix = "GML"
),
public = list(

timeCS = NULL,
temporalDatum = NULL,

#setTimeCS
setTimeCS = function(timeCS){
if(!is(timeCS, "GMLTimeCS")){
stop("The argument should be an object of class 'GMLTimeCS")
}
self$timeCS <- GMLElement$create("timeCS", timeCS)
},

#setTemporalDatum
setTemporalDatum = function(temporalDatum){
if(!is(temporalDatum, "GMLTemporalDatum")){
stop("The argument should be an object of class 'GMLTemporalDatum")
}
self$temporalDatum <- GMLElement$create("temporalDatum", temporalDatum)
}

)
)
12 changes: 11 additions & 1 deletion R/ISOAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,17 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
#more than one child, consider it as sequence
fieldClass <- ISOElementSequence
}

}else{
#if xlink:href attr available attempt to
href <- xmlGetAttr(child, "xlink:href")
if(!is.null(href)){
self$INFO(sprintf("Fetching child elemnt from xlink:href attribute '%s'", href))
child <- try(XML::xmlParse(href))
if(!is(child,"try-error")){
child <- XML::xmlRoot(child)
fieldClass <- ISOAbstractObject$getISOClassByNode(child)
}
}
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions man/GMLCompoundCRS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions man/GMLTemporalCRS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions tests/testthat/test_GMLCompoundCRS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# test_GMLCompoundCRS.R
# Author: Emmanuel Blondel <[email protected]>
#
# Description: Unit tests for GMLCompoundCRS.R
#=======================
require(geometa, quietly = TRUE)
require(testthat)
require(XML)

context("GMLCompoundCRS")

test_that("encoding",{

#encoding
gml <- GMLCompoundCRS$new()
gml$setDescriptionReference("someref")
gml$setIdentifier("test", "codespace")
gml$addScope("somescope")

xml <- gml$encode()
expect_is(xml, "XMLInternalNode")

#decoding
gml2 <- GMLCompoundCRS$new(xml = xml)
xml2 <- gml2$encode(validate=F)

expect_true(ISOAbstractObject$compare(gml, gml2))

})

0 comments on commit 299c6aa

Please sign in to comment.