-
Notifications
You must be signed in to change notification settings - Fork 5
/
GMLConventionalUnit.R
97 lines (94 loc) · 3.5 KB
/
GMLConventionalUnit.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#' GMLConventionalUnit
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO GML conventional unit definition
#' @return Object of \code{\link{R6Class}} for modelling an GML derived unit
#' @format \code{\link{R6Class}} object.
#'
#' @field conversionToPreferredUnit [\code{\link{GMLElement}}]
#' @field roughConversionToPreferredUnit [\code{\link{GMLElement}}]
#' @field derivationUnitTerm [\code{\link{GMLElement}}]
#'
#' @section Methods:
#' \describe{
#' \item{\code{new(xml, defaults, id)}}{
#' This method is used to instantiate a GML Base Unit
#' }
#' \item{\code{addDerivationUnitTerm(uom, exponent)}}{
#' Adds a derivation unit term, made of a uom reference, and an exponent which
#' can be negative/positive but not equal to zero.
#' }
#' \item{\code{delDerivationUnitTerm(uom, exponent)}}{
#' Deletes a derivation unit term
#' }
#' \item{\code{setConversionToPreferredUnit(uom, factor, rough)}}{
#' Sets the conversion to preferred unit. \code{rough} is \code{FALSE} by default
#' }
#' }
#'
#' @examples
#' gml <- GMLConventionalUnit$new()
#' gml$setDescriptionReference("someref")
#' gml$setIdentifier("identifier", "codespace")
#' gml$addName("name1", "codespace")
#' gml$addName("name2", "codespace")
#' gml$setQuantityTypeReference("someref")
#' gml$setCatalogSymbol("symbol")
#' gml$addDerivationUnitTerm("uomId", 2L)
#' gml$setConversionToPreferredUnit("uomId", 2L)
#'
#' @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>
#'
GMLConventionalUnit <- R6Class("GMLConventionalUnit",
inherit = GMLUnitDefinition,
private = list(
xmlElement = "ConventionalUnit",
xmlNamespacePrefix = "GML"
),
public = list(
#+ conversionToPreferredUnit [1..1]: character/integer
conversionToPreferredUnit = NULL,
#+ conversionToPreferredUnit [1..1]: character/integer
roughConversionToPreferredUnit = NULL,
#+ derivationUnitTerm [1..*]: character
derivationUnitTerm = NULL,
initialize = function(xml = NULL, defaults = list(), id = NULL){
super$initialize(xml, defaults)
if(is.null(xml)){
self$setId(id, addNS = TRUE)
}
},
#addDerivationUnitTerm
addDerivationUnitTerm = function(uom, exponent){
if(exponent == 0L){
stop("Exponent argument value cannot be equal to zero")
}
gmlElem <- GMLElement$create("derivationUnitTerm", attrs = list(uom = uom, exponent = exponent))
return(self$addListElement("derivationUnitTerm", gmlElem))
},
#delDerivationUnitTerm
delDerivationUnitTerm = function(uom, exponent){
if(exponent == 0L){
stop("Exponent argument value cannot be equal to zero")
}
gmlElem <- GMLElement$create("derivationUnitTerm", attrs = list(uom = uom, exponent = exponent))
return(self$delListElement("derivationUnitTerm", gmlElem))
},
#setConversionToPreferredUnit
setConversionToPreferredUnit = function(uom, factor, rough = FALSE){
elem <- ifelse(rough, "roughConversionToPreferredUnit", "conversionToPreferredUnit")
gmlElem <- GMLElement$create(elem, attrs = list(uom = uom))
gmlFactorElem <- GMLElement$create("factor", value = factor)
gmlElem[["factor"]] <- gmlFactorElem
self[[elem]] <- gmlElem
}
)
)