From ec3f45e4a81857e5611fb158c868cfa1b7499dd2 Mon Sep 17 00:00:00 2001 From: eblondel Date: Mon, 3 Oct 2022 09:04:20 +0200 Subject: [PATCH] #187 SWE encoding elements, Rdoc --- NAMESPACE | 3 ++ R/SWEAbstractEncoding.R | 31 +++++++++++++ R/SWENilValues.R | 1 - R/SWETextEncoding.R | 43 +++++++++++++++++++ R/SWEXMLEncoding.R | 29 +++++++++++++ README.md | 2 +- .../coverage/geometa_coverage_inventory.csv | 6 +-- .../coverage/geometa_coverage_summary.csv | 2 +- .../coverage/geometa_coverage_summary.md | 2 +- man/SWEAbstractDataComponent.Rd | 8 ++-- man/SWEAbstractEncoding.Rd | 26 +++++++++++ man/SWENilValues.Rd | 2 - man/SWETextEncoding.Rd | 36 ++++++++++++++++ man/SWETimeRange.Rd | 4 +- man/SWEXMLEncoding.Rd | 26 +++++++++++ tests/testthat/test_SWE_encodings.R | 36 ++++++++++++++++ 16 files changed, 243 insertions(+), 14 deletions(-) create mode 100644 R/SWEAbstractEncoding.R create mode 100644 R/SWETextEncoding.R create mode 100644 R/SWEXMLEncoding.R create mode 100644 man/SWEAbstractEncoding.Rd create mode 100644 man/SWETextEncoding.Rd create mode 100644 man/SWEXMLEncoding.Rd create mode 100644 tests/testthat/test_SWE_encodings.R diff --git a/NAMESPACE b/NAMESPACE index 0ae79890..a983fe2d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -320,6 +320,7 @@ export(ISOUsage) export(ISOVectorSpatialRepresentation) export(ISOVerticalExtent) export(SWEAbstractDataComponent) +export(SWEAbstractEncoding) export(SWEAbstractObject) export(SWEAbstractSWE) export(SWEAbstractSimpleComponent) @@ -333,8 +334,10 @@ export(SWENilValues) export(SWEQuantity) export(SWEQuantityRange) export(SWEText) +export(SWETextEncoding) export(SWETime) export(SWETimeRange) +export(SWEXMLEncoding) export(cacheISOClasses) export(convert_metadata) export(geometaLogger) diff --git a/R/SWEAbstractEncoding.R b/R/SWEAbstractEncoding.R new file mode 100644 index 00000000..c5ada695 --- /dev/null +++ b/R/SWEAbstractEncoding.R @@ -0,0 +1,31 @@ +#' SWEAbstractEncoding +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO SWE +#' @return Object of \code{\link{R6Class}} for modelling an SWE abstract encoding object +#' @format \code{\link{R6Class}} object. +#' +#' @references +#' SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon +#' +#' @author Emmanuel Blondel +#' +SWEAbstractEncoding <- R6Class("SWEAbstractEncoding", + inherit = SWEAbstractSWE, + private = list( + xmlElement = "AbstractEncoding", + xmlNamespacePrefix = "SWE" + ), + public = list( + + #'@description Initializes a SWE Nil Values object + #'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML} + initialize = function(xml = NULL){ + super$initialize(xml, element = private$xmlElement, + attrs = list(), defaults = list(), + wrap = TRUE) + } + ) +) \ No newline at end of file diff --git a/R/SWENilValues.R b/R/SWENilValues.R index 89dacacf..e367a40d 100644 --- a/R/SWENilValues.R +++ b/R/SWENilValues.R @@ -25,7 +25,6 @@ SWENilValues <- R6Class("SWENilValues", #'@description Initializes a SWE Nil Values object #'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML} - #'@param values vector of numerical values to consider as nil values initialize = function(xml = NULL){ super$initialize(xml, element = private$xmlElement, attrs = list(), defaults = list(), diff --git a/R/SWETextEncoding.R b/R/SWETextEncoding.R new file mode 100644 index 00000000..1dffd36c --- /dev/null +++ b/R/SWETextEncoding.R @@ -0,0 +1,43 @@ +#' SWETextEncoding +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO SWE +#' @return Object of \code{\link{R6Class}} for modelling an SWE text encoding object +#' @format \code{\link{R6Class}} object. +#' +#' @references +#' SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon +#' +#' @author Emmanuel Blondel +#' +SWETextEncoding <- R6Class("SWETextEncoding", + inherit = SWEAbstractEncoding, + private = list( + xmlElement = "TextEncoding", + xmlNamespacePrefix = "SWE" + ), + public = list( + + #'@description Initializes a SWE Text Encoding element + #'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML} + #'@param collapseWhiteSpaces Indicates whether white spaces (i.e. space, tab, CR, LF) + #' should be collapsed with separators when parsing the data stream. Default is \code{TRUE} + #'@param decimalSeparator Character used as the decimal separator. Default is \code{TRUE} + #'@param tokenSeparator Character sequence used as the token separator (i.e. between two successive values). Required + #'@param blockSeparator Character sequence used as the block separator (i.e. between two successive blocks in the data set. + #' The end of a block is reached once all values from the data tree have been encoded once). Required + #' + initialize = function(xml = NULL, collapseWhiteSpaces = TRUE, decimalSeparator = ".", + tokenSeparator = NULL, blockSeparator = NULL){ + super$initialize(xml = xml) + if(is.null(xml)){ + self$setAttr("collapseWhiteSpaces", tolower(collapseWhiteSpaces)) + self$setAttr("decimalSeparator", decimalSeparator) + self$setAttr("tokenSeparator", tokenSeparator) + self$setAttr("blockSeparator", blockSeparator) + } + } + ) +) \ No newline at end of file diff --git a/R/SWEXMLEncoding.R b/R/SWEXMLEncoding.R new file mode 100644 index 00000000..27b3f872 --- /dev/null +++ b/R/SWEXMLEncoding.R @@ -0,0 +1,29 @@ +#' SWEXMLEncoding +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO SWE +#' @return Object of \code{\link{R6Class}} for modelling an SWE XML encoding object +#' @format \code{\link{R6Class}} object. +#' +#' @references +#' SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon +#' +#' @author Emmanuel Blondel +#' +SWEXMLEncoding <- R6Class("SWEXMLEncoding", + inherit = SWEAbstractEncoding, + private = list( + xmlElement = "XMLEncoding", + xmlNamespacePrefix = "SWE" + ), + public = list( + + #'@description Initializes a SWE XML Encoding element + #'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML} + initialize = function(xml = NULL){ + super$initialize(xml = xml) + } + ) +) \ No newline at end of file diff --git a/README.md b/README.md index 3a73c1a4..de2e2112 100644 --- a/README.md +++ b/README.md @@ -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/-50%25-f9ae2c.svg)](https://github.com/eblondel/geometa) | 15| 15| +|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-60%25-f2eb24.svg)](https://github.com/eblondel/geometa) | 18| 12| diff --git a/inst/extdata/coverage/geometa_coverage_inventory.csv b/inst/extdata/coverage/geometa_coverage_inventory.csv index aeaccb12..ea1ea6fb 100644 --- a/inst/extdata/coverage/geometa_coverage_inventory.csv +++ b/inst/extdata/coverage/geometa_coverage_inventory.csv @@ -473,7 +473,7 @@ "GML 3.3 Referenceable Grid (OGC GML)","OGC GML Referenceable Grid","GMLRGRID","ReferenceableGridByTransformation","GMLReferenceableGridByTransformation",TRUE "GML 3.3 Referenceable Grid (OGC GML)","OGC GML Referenceable Grid","GMLRGRID","ReferenceableGridByVectors","GMLReferenceableGridByVectors",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","AbstractDataComponent","SWEAbstractDataComponent",TRUE -"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","AbstractEncoding","",FALSE +"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","AbstractEncoding","SWEAbstractEncoding",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","AbstractObject","SWEAbstractObject",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","AbstractSimpleComponent","SWEAbstractSimpleComponent",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","AbstractSWE","SWEAbstractSWE",TRUE @@ -497,8 +497,8 @@ "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Quantity","SWEQuantity",TRUE "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","",FALSE +"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","TextEncoding","SWETextEncoding",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Time","SWETime",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","TimeRange","SWETimeRange",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Vector","",FALSE -"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","XMLEncoding","",FALSE +"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","XMLEncoding","SWEXMLEncoding",TRUE diff --git a/inst/extdata/coverage/geometa_coverage_summary.csv b/inst/extdata/coverage/geometa_coverage_summary.csv index 0278b85c..4c40cd5f 100644 --- a/inst/extdata/coverage/geometa_coverage_summary.csv +++ b/inst/extdata/coverage/geometa_coverage_summary.csv @@ -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",15,15,50 +"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE",18,12,60 diff --git a/inst/extdata/coverage/geometa_coverage_summary.md b/inst/extdata/coverage/geometa_coverage_summary.md index be35b69f..20b3d92b 100644 --- a/inst/extdata/coverage/geometa_coverage_summary.md +++ b/inst/extdata/coverage/geometa_coverage_summary.md @@ -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/-50%25-f9ae2c.svg)](https://github.com/eblondel/geometa) | 15| 15| +|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-60%25-f2eb24.svg)](https://github.com/eblondel/geometa) | 18| 12| diff --git a/man/SWEAbstractDataComponent.Rd b/man/SWEAbstractDataComponent.Rd index f49ac760..44347f6a 100644 --- a/man/SWEAbstractDataComponent.Rd +++ b/man/SWEAbstractDataComponent.Rd @@ -20,6 +20,8 @@ \item{description}{description} +\item{label}{label} + \item{name}{name} \item{codeSpace}{codespace} @@ -32,10 +34,10 @@ Object of \code{\link{R6Class}} for modelling an SWE Abstract data component \description{ Initializes an object of class \link{SWEAbstractDataComponent} -Set definition - Set description +Set label + Adds name Deletes name @@ -45,8 +47,6 @@ Set identifier \section{Fields}{ \describe{ -\item{\code{definition}}{definition} - \item{\code{description}}{description} \item{\code{label}}{label} diff --git a/man/SWEAbstractEncoding.Rd b/man/SWEAbstractEncoding.Rd new file mode 100644 index 00000000..92931b62 --- /dev/null +++ b/man/SWEAbstractEncoding.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SWEAbstractEncoding.R +\docType{class} +\name{SWEAbstractEncoding} +\alias{SWEAbstractEncoding} +\title{SWEAbstractEncoding} +\format{ +\code{\link{R6Class}} object. +} +\arguments{ +\item{xml}{object of class \link{XMLInternalNode-class} from \pkg{XML}} +} +\value{ +Object of \code{\link{R6Class}} for modelling an SWE abstract encoding object +} +\description{ +Initializes a SWE Nil Values object +} +\references{ +SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon +} +\author{ +Emmanuel Blondel +} +\keyword{ISO} +\keyword{SWE} diff --git a/man/SWENilValues.Rd b/man/SWENilValues.Rd index 660bd10f..39ebbec7 100644 --- a/man/SWENilValues.Rd +++ b/man/SWENilValues.Rd @@ -10,8 +10,6 @@ \arguments{ \item{xml}{object of class \link{XMLInternalNode-class} from \pkg{XML}} -\item{values}{vector of numerical values to consider as nil values} - \item{value}{value} \item{reason}{reason} diff --git a/man/SWETextEncoding.Rd b/man/SWETextEncoding.Rd new file mode 100644 index 00000000..c7fba6d3 --- /dev/null +++ b/man/SWETextEncoding.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SWETextEncoding.R +\docType{class} +\name{SWETextEncoding} +\alias{SWETextEncoding} +\title{SWETextEncoding} +\format{ +\code{\link{R6Class}} object. +} +\arguments{ +\item{xml}{object of class \link{XMLInternalNode-class} from \pkg{XML}} + +\item{collapseWhiteSpaces}{Indicates whether white spaces (i.e. space, tab, CR, LF) +should be collapsed with separators when parsing the data stream. Default is \code{TRUE}} + +\item{decimalSeparator}{Character used as the decimal separator. Default is \code{TRUE}} + +\item{tokenSeparator}{Character sequence used as the token separator (i.e. between two successive values). Required} + +\item{blockSeparator}{Character sequence used as the block separator (i.e. between two successive blocks in the data set. +The end of a block is reached once all values from the data tree have been encoded once). Required} +} +\value{ +Object of \code{\link{R6Class}} for modelling an SWE text encoding object +} +\description{ +Initializes a SWE Text Encoding element +} +\references{ +SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon +} +\author{ +Emmanuel Blondel +} +\keyword{ISO} +\keyword{SWE} diff --git a/man/SWETimeRange.Rd b/man/SWETimeRange.Rd index baf6158a..2fe2cfbc 100644 --- a/man/SWETimeRange.Rd +++ b/man/SWETimeRange.Rd @@ -20,7 +20,9 @@ \item{constraint}{constraint} -\item{value}{value} +\item{start}{start time} + +\item{end}{end time} } \value{ Object of \code{\link{R6Class}} for modelling an SWE Time Range diff --git a/man/SWEXMLEncoding.Rd b/man/SWEXMLEncoding.Rd new file mode 100644 index 00000000..94deaba9 --- /dev/null +++ b/man/SWEXMLEncoding.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SWEXMLEncoding.R +\docType{class} +\name{SWEXMLEncoding} +\alias{SWEXMLEncoding} +\title{SWEXMLEncoding} +\format{ +\code{\link{R6Class}} object. +} +\arguments{ +\item{xml}{object of class \link{XMLInternalNode-class} from \pkg{XML}} +} +\value{ +Object of \code{\link{R6Class}} for modelling an SWE XML encoding object +} +\description{ +Initializes a SWE XML Encoding element +} +\references{ +SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon +} +\author{ +Emmanuel Blondel +} +\keyword{ISO} +\keyword{SWE} diff --git a/tests/testthat/test_SWE_encodings.R b/tests/testthat/test_SWE_encodings.R new file mode 100644 index 00000000..8136ab46 --- /dev/null +++ b/tests/testthat/test_SWE_encodings.R @@ -0,0 +1,36 @@ +# test_SWE_encodings.R +# Author: Emmanuel Blondel +# +# Description: Unit tests for classes inheriting SWEAbstractEncoding.R +#======================= +require(geometa, quietly = TRUE) +require(sf) +require(testthat) + +context("SWE encodings") + +test_that("SWEXMLEncoding",{ + testthat::skip_on_cran() + #encoding + enc <- SWEXMLEncoding$new() + xml <- enc$encode() + expect_is(xml, "XMLInternalNode") + #decoding + enc2 <- SWEXMLEncoding$new(xml = xml) + xml2 <- enc2$encode() + #assert object identity + expect_true(ISOAbstractObject$compare(enc, enc2)) +}) + +test_that("SWETextEncoding",{ + testthat::skip_on_cran() + #encoding + enc <- SWETextEncoding$new(tokenSeparator = " ", blockSeparator = ",") + xml <- enc$encode() + expect_is(xml, "XMLInternalNode") + #decoding + enc2 <- SWETextEncoding$new(xml = xml) + xml2 <- enc2$encode() + #assert object identity + expect_true(ISOAbstractObject$compare(enc, enc2)) +})