Skip to content

Commit

Permalink
#187 further work on SWE components, QuantityRange
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed May 9, 2022
1 parent 98a974b commit dca3571
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 30 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export(SWEAbstractDataComponent)
export(SWEAbstractObject)
export(SWEAbstractSimpleComponent)
export(SWECount)
export(SWEQuantityRange)
export(SWEText)
export(cacheISOClasses)
export(convert_metadata)
Expand Down
11 changes: 10 additions & 1 deletion R/ISOAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,16 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
}), collapse = " ")
txtNode <- xmlTextNode(mts)
if(field == "value"){
rootXML$addNode(txtNode)
if(field == "value" && self$value_as_field){
wrapperNode <- xmlOutputDOM(
tag = field,
nameSpace = namespaceId
)
wrapperNode$addNode(txtNode)
rootXML$addNode(wrapperNode$value())
}else{
rootXML$addNode(txtNode)
}
}else{
wrapperNode <- xmlOutputDOM(tag = field, nameSpace = namespaceId)
wrapperNode$addNode(txtNode)
Expand Down
13 changes: 8 additions & 5 deletions R/SWEAbstractDataComponent.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ SWEAbstractDataComponent <- R6Class("SWEAbstractDataComponent",
#'@description Initializes an object of class \link{SWEAbstractDataComponent}
#'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML}
#'@param element element
#'@param attrs attrs
#'@param defaults defaults
#'@param wrap wrap
initialize = function(xml = NULL, element = NULL, attrs = list(), defaults = list(), wrap = TRUE){
#'@param updatable updatable
#'@param optional optional
#'@param definition definition
initialize = function(xml = NULL, element = NULL, updatable = NULL, optional = FALSE, definition = NULL){
if(is.null(element)) element <- private$xmlElement
super$initialize(xml, element = element, attrs = attrs, defaults = defaults, wrap = wrap)
super$initialize(xml, element = element, attrs = list(), defaults = list(), wrap = FALSE)
if(!is.null(updatable)) if(is.logical(updatable)) self$setAttr("updatable", tolower(updatable))
self$setAttr("optional", tolower(optional))
if(!is.null(definition)) self$setAttr("definition", definition)
},

#'@description Set definition
Expand Down
10 changes: 5 additions & 5 deletions R/SWEAbstractSimpleComponent.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ SWEAbstractSimpleComponent <- R6Class("SWEAbstractSimpleComponent",
#'@description Initializes an object of class \link{SWEAbstractSimpleComponent}
#'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML}
#'@param element element
#'@param attrs attrs
#'@param defaults defaults
#'@param wrap wrap
initialize = function(xml = NULL, element = NULL, attrs = list(), defaults = list(), wrap = TRUE){
#'@param updatable updatable
#'@param optional optional
#'@param definition definition
initialize = function(xml = NULL, element = NULL, updatable = NULL, optional = FALSE, definition = NULL){
if(is.null(element)) element <- private$xmlElement
super$initialize(xml, element = element, attrs = attrs, defaults = defaults, wrap = wrap)
super$initialize(xml, element = element, updatable = updatable, optional = optional, definition = definition)
}
)
)
14 changes: 10 additions & 4 deletions R/SWECount.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,28 @@ SWECount <- R6Class("SWECount",
#'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML}
#'@param constraint constraint
#'@param value value
initialize = function(xml = NULL, constraint = NULL, value = NULL){
super$initialize(xml, element = private$xmlElement)
#'@param updatable updatable
#'@param optional optional
#'@param definition definition
initialize = function(xml = NULL,
constraint = NULL, value = NULL,
updatable = NULL, optional = FALSE, definition = NULL){
super$initialize(xml, element = private$xmlElement,
updatable = updatable, optional = optional, definition = definition)
if(is.null(xml)){
self$constraint <- constraint
self$value <- value
}
},

#'@description setConstraint
#'@param constraint
#'@param constraint constraint
setConstraint = function(constraint){
self$constraint <- constraint
},

#'@description setValue
#'@param value
#'@param value value
setValue = function(value){
self$value <- value
}
Expand Down
82 changes: 82 additions & 0 deletions R/SWEQuantityRange.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#' SWEQuantityRange
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO SWE
#' @return Object of \code{\link{R6Class}} for modelling an SWE QuantityRange
#' @format \code{\link{R6Class}} object.
#'
#' @references
#' OGC Geography Markup Language. https://www.ogc.org/standards/swecommon
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
SWEQuantityRange <- R6Class("SWEQuantityRange",
inherit = SWEAbstractSimpleComponent,
private = list(
xmlElement = "QuantityRange",
xmlNamespacePrefix = "SWE"
),
public = list(

#'@field uom uom
uom = NULL,

#'@field constraint constraint
constraint = NULL,

#'@field value value
value = matrix(NA_real_, 1, 2),

#'@description Initializes an object of class \link{SWEQuantityRange}
#'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML}
#'@param constraint constraint
#'@param value value
#'@param updatable updatable
#'@param optional optional
#'@param definition definition
initialize = function(xml = NULL,
constraint = NULL, value = NULL,
updatable = NULL, optional = FALSE, definition = NULL){
super$initialize(xml, element = private$xmlElement,
updatable = updatable, optional = optional, definition = definition)
if(is.null(xml)){
self$setConstraint(constraint)
self$setValue(value)
}
},

#'@description setUom
#'@param uom uom
setUom = function(uom){
self$uom <- uom
},

#'@description setConstraint
#'@param constraint constraint
setConstraint = function(constraint){
self$constraint <- constraint
},

#'@description setValue
#'@param value value
setValue = function(value){
if(!is.numeric(value)){
stop("Values should be numeric")
}
if(is.vector(value)){
if(length(value)!="2"){
stop("Vector of values should of length 2")
}
}else if(is.matrix(value)){
if(!all(dim(value)==c(1,2))){
stop("Matrix of values should be of dimensions 1,2")
}
}else{
stop("Value should be either a vector or matrix")
}
self$value <- value
}
)
)
14 changes: 10 additions & 4 deletions R/SWEText.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,28 @@ SWEText <- R6Class("SWEText",
#'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML}
#'@param constraint constraint
#'@param value value
initialize = function(xml = NULL, constraint = NULL, value = NULL){
super$initialize(xml, element = private$xmlElement)
#'@param updatable updatable
#'@param optional optional
#'@param definition definition
initialize = function(xml = NULL,
constraint = NULL, value = NULL,
updatable = NULL, optional = FALSE, definition = NULL){
super$initialize(xml, element = private$xmlElement,
updatable = updatable, optional = optional, definition = definition)
if(is.null(xml)){
self$constraint <- constraint
self$value <- value
}
},

#'@description setConstraint
#'@param constraint
#'@param constraint constraint
setConstraint = function(constraint){
self$constraint <- constraint
},

#'@description setValue
#'@param value
#'@param value value
setValue = function(value){
self$value <- value
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ We thank in advance people that use ``geometa`` for citing it in their work / pu
|GML 3.2.1 (ISO 19136) |Geographic Markup Language |GML |[![GML 3.2.1 (ISO 19136)](https://img.shields.io/badge/-37%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 63| 106|
|GML 3.2.1 Coverage (OGC GMLCOV) |OGC GML Coverage Implementation Schema |GMLCOV |[![GML 3.2.1 Coverage (OGC GMLCOV)](https://img.shields.io/badge/-100%25-4a4ea8.svg)](https://github.com/eblondel/geometa) | 1| 0|
|GML 3.3 Referenceable Grid (OGC GML) |OGC GML Referenceable Grid |GMLRGRID |[![GML 3.3 Referenceable Grid (OGC GML)](https://img.shields.io/badge/-100%25-4a4ea8.svg)](https://github.com/eblondel/geometa) | 5| 0|
|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-17%25-ad0f0f.svg)](https://github.com/eblondel/geometa) | 5| 25|
|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-20%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 6| 24|
2 changes: 1 addition & 1 deletion inst/extdata/coverage/geometa_coverage_inventory.csv
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Matrix","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","NilValues","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Quantity","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","QuantityRange","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","QuantityRange","SWEQuantityRange",TRUE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Text","SWEText",TRUE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","TextEncoding","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Time","<missing>",FALSE
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/coverage/geometa_coverage_summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"GML 3.2.1 (ISO 19136)","Geographic Markup Language","GML",63,106,37.28
"GML 3.2.1 Coverage (OGC GMLCOV)","OGC GML Coverage Implementation Schema","GMLCOV",1,0,100
"GML 3.3 Referenceable Grid (OGC GML)","OGC GML Referenceable Grid","GMLRGRID",5,0,100
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE",5,25,16.67
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE",6,24,20
2 changes: 1 addition & 1 deletion inst/extdata/coverage/geometa_coverage_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
|GML 3.2.1 (ISO 19136) |Geographic Markup Language |GML |[![GML 3.2.1 (ISO 19136)](https://img.shields.io/badge/-37%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 63| 106|
|GML 3.2.1 Coverage (OGC GMLCOV) |OGC GML Coverage Implementation Schema |GMLCOV |[![GML 3.2.1 Coverage (OGC GMLCOV)](https://img.shields.io/badge/-100%25-4a4ea8.svg)](https://github.com/eblondel/geometa) | 1| 0|
|GML 3.3 Referenceable Grid (OGC GML) |OGC GML Referenceable Grid |GMLRGRID |[![GML 3.3 Referenceable Grid (OGC GML)](https://img.shields.io/badge/-100%25-4a4ea8.svg)](https://github.com/eblondel/geometa) | 5| 0|
|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-17%25-ad0f0f.svg)](https://github.com/eblondel/geometa) | 5| 25|
|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-20%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 6| 24|
6 changes: 2 additions & 4 deletions man/SWEAbstractDataComponent.Rd

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

6 changes: 3 additions & 3 deletions man/SWEAbstractSimpleComponent.Rd

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

6 changes: 6 additions & 0 deletions man/SWECount.Rd

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

54 changes: 54 additions & 0 deletions man/SWEQuantityRange.Rd

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

6 changes: 6 additions & 0 deletions man/SWEText.Rd

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

23 changes: 23 additions & 0 deletions tests/testthat/test_SWEQuantityRange.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# test_SWEQuantityRange.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for classes inheriting SWEQuantityRange.R
#=======================
require(geometa, quietly = TRUE)
require(sf)
require(testthat)

conQuantityRange("SWEQuantityRange")

test_that("SWEQuantityRange",{
testthat::skip_on_cran()
#encoding
qr <- SWEQuantityRange$new(value = matrix(c(0,1),1,2))
xml <- qr$encode()
expect_is(xml, "XMLInternalNode")
#decoding
qr2 <- SWEQuantityRange$new(xml = xml)
xml2 <- qr2$encode()
#assert object identity
expect_true(ISOAbstractObject$compare(qr, qr2))
})

0 comments on commit dca3571

Please sign in to comment.