Skip to content

Commit

Permalink
eblondel#187 SWE AbstractSimpleComponent, Count
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed May 9, 2022
1 parent 614c1c4 commit 16a1483
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 15 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export(ISOVerticalExtent)
export(SWEAbstractDataComponent)
export(SWEAbstractObject)
export(SWEAbstractSimpleComponent)
export(SWECount)
export(cacheISOClasses)
export(convert_metadata)
export(geometaLogger)
Expand Down
19 changes: 15 additions & 4 deletions R/ISOAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
xmlNamespacePrefix = "GCO",
encoding = options("encoding"),
document = FALSE,
system_fields = c("wrap", "valueDescription",
system_fields = c("wrap", "value_as_field", "valueDescription",
"element", "namespace", "defaults", "attrs", "printAttrs", "parentAttrs",
"codelistId", "measureType", "isNull", "anyElement"),
xmlComments = function(isoCompliant = NA, inspireReport = NULL){
Expand Down Expand Up @@ -319,18 +319,20 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
printAttrs = list(),
parentAttrs = NULL,
value = NULL,
value_as_field = FALSE,
isNull = FALSE,
anyElement = FALSE,
initialize = function(xml = NULL, element = NULL, namespace = NULL,
attrs = list(), defaults = list(),
wrap = TRUE){
wrap = TRUE, value_as_field = FALSE){
if(!is.null(element)){ private$xmlElement <- element }
if(!is.null(namespace)){ private$xmlNamespacePrefix <- toupper(namespace)}
self$element = private$xmlElement
self$namespace = getISOMetadataNamespace(private$xmlNamespacePrefix)
self$attrs = attrs
self$defaults = defaults
self$wrap = wrap
self$value_as_field = value_as_field
if(!is.null(xml)){
self$decode(xml)
}
Expand Down Expand Up @@ -934,10 +936,19 @@ ISOAbstractObject <- R6Class("ISOAbstractObject",
emptyNode <- xmlOutputDOM(tag = field,nameSpace = namespaceId, attrs = emptyNodeAttrs)
rootXML$addNode(emptyNode$value())
}else{
if(field == "value"|| field == "_internal_"){
if((field == "value"|| field == "_internal_")){
if(is.logical(fieldObj)) fieldObj <- tolower(as.character(is.logical(fieldObj)))
fieldObj <- private$fromComplexTypes(fieldObj)
rootXML$addNode(xmlTextNode(fieldObj))
if(field == "value" && self$value_as_field){
wrapperNode <- xmlOutputDOM(
tag = field,
nameSpace = namespaceId
)
wrapperNode$addNode(xmlTextNode(fieldObj))
rootXML$addNode(wrapperNode$value())
}else{
rootXML$addNode(xmlTextNode(fieldObj))
}
}else{
dataObj <- self$wrapBaseElement(field, fieldObj)
if(!is.null(dataObj)){
Expand Down
2 changes: 1 addition & 1 deletion R/SWEAbstractDataComponent.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO SWE
#' @return Object of \code{\link{R6Class}} for modelling an SWS Abstract data component
#' @return Object of \code{\link{R6Class}} for modelling an SWE Abstract data component
#' @format \code{\link{R6Class}} object.
#'
#' @note Class used internally by geometa
Expand Down
4 changes: 2 additions & 2 deletions R/SWEAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO GML
#' @return Object of \code{\link{R6Class}} for modelling an GML abstract object
#' @return Object of \code{\link{R6Class}} for modelling an SWE abstract object
#' @format \code{\link{R6Class}} object.
#'
#' @note Class used internally by geometa
Expand All @@ -29,7 +29,7 @@ SWEAbstractObject <- R6Class("SWEAbstractObject",
if(is.null(element)) element <- private$xmlElement
super$initialize(xml, element, namespace = private$xmlNamespacePrefix,
attrs = attrs, defaults = defaults,
wrap = wrap)
wrap = wrap, value_as_field = TRUE)
}
)
)
2 changes: 1 addition & 1 deletion R/SWEAbstractSimpleComponent.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO SWE
#' @return Object of \code{\link{R6Class}} for modelling an SWS Abstract simple component
#' @return Object of \code{\link{R6Class}} for modelling an SWE Abstract simple component
#' @format \code{\link{R6Class}} object.
#'
#' @references
Expand Down
55 changes: 55 additions & 0 deletions R/SWECount.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' SWECount
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO SWE
#' @return Object of \code{\link{R6Class}} for modelling an SWE Count
#' @format \code{\link{R6Class}} object.
#'
#' @references
#' OGC Geography Markup Language. https://www.ogc.org/standards/swecommon
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
SWECount <- R6Class("SWECount",
inherit = SWEAbstractSimpleComponent,
private = list(
xmlElement = "Count",
xmlNamespacePrefix = "SWE"
),
public = list(

#'@field constraint constraint
constraint = NULL,

#'@field value value
value = NULL,

#'@description Initializes an object of class \link{SWECount}
#'@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, constraint = NULL, value = NULL){
super$initialize(xml, element = private$xmlElement)
if(is.null(xml)){
self$constraint <- constraint
self$value <- value
}
},

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

#'@description setValue
#'@param value
setValue = function(value){
self$value <- value
}
)
)
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/-7%25-ad0f0f.svg)](https://github.com/eblondel/geometa) | 2| 28|
|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-16%25-ad0f0f.svg)](https://github.com/eblondel/geometa) | 5| 26|
3 changes: 2 additions & 1 deletion inst/extdata/coverage/geometa_coverage_inventory.csv
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Category","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","CategoryRange","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Component","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Count","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Count","SWECount",TRUE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Count","SWECount",TRUE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","CountRange","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","DataArray","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","DataChoice","<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",3,27,10
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE",5,26,16.13
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/-10%25-ad0f0f.svg)](https://github.com/eblondel/geometa) | 3| 27|
|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-16%25-ad0f0f.svg)](https://github.com/eblondel/geometa) | 5| 26|
2 changes: 1 addition & 1 deletion man/SWEAbstractDataComponent.Rd

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

2 changes: 1 addition & 1 deletion man/SWEAbstractObject.Rd

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

2 changes: 1 addition & 1 deletion man/SWEAbstractSimpleComponent.Rd

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

46 changes: 46 additions & 0 deletions man/SWECount.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_SWECount.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# test_SWECount.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for classes inheriting SWECount.R
#=======================
require(geometa, quietly = TRUE)
require(sf)
require(testthat)

context("SWECount")

test_that("SWECount",{
testthat::skip_on_cran()
#encoding
cnt <- SWECount$new(value = 1000)
xml <- cnt$encode()
expect_is(xml, "XMLInternalNode")
#decoding
cnt2 <- SWECount$new(xml = xml)
xml2 <- cnt2$encode()
#assert object identity
expect_true(ISOAbstractObject$compare(cnt, cnt2))
})

0 comments on commit 16a1483

Please sign in to comment.