From 62f0dc814fdb3055520fdd8e005973669433577a Mon Sep 17 00:00:00 2001 From: eblondel Date: Thu, 12 May 2022 14:46:46 +0200 Subject: [PATCH] #187 SWECategoryRange --- NAMESPACE | 1 + R/SWECategoryRange.R | 84 +++++++++++++++++++ README.md | 2 +- .../coverage/geometa_coverage_inventory.csv | 2 +- .../coverage/geometa_coverage_summary.csv | 2 +- .../coverage/geometa_coverage_summary.md | 2 +- man/SWECategoryRange.Rd | 54 ++++++++++++ tests/testthat/test_SWECategoryRange.R | 23 +++++ 8 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 R/SWECategoryRange.R create mode 100644 man/SWECategoryRange.Rd create mode 100644 tests/testthat/test_SWECategoryRange.R diff --git a/NAMESPACE b/NAMESPACE index 7ee29fef..96d66991 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -322,6 +322,7 @@ export(ISOVerticalExtent) export(SWEAbstractDataComponent) export(SWEAbstractObject) export(SWEAbstractSimpleComponent) +export(SWECategoryRange) export(SWECount) export(SWEQuantityRange) export(SWEText) diff --git a/R/SWECategoryRange.R b/R/SWECategoryRange.R new file mode 100644 index 00000000..d9f208e7 --- /dev/null +++ b/R/SWECategoryRange.R @@ -0,0 +1,84 @@ +#' SWECategoryRange +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO SWE +#' @return Object of \code{\link{R6Class}} for modelling an SWE CategoryRange +#' @format \code{\link{R6Class}} object. +#' +#' @references +#' OGC Geography Markup Language. https://www.ogc.org/standards/swecommon +#' +#' @author Emmanuel Blondel +#' +SWECategoryRange <- R6Class("SWECategoryRange", + inherit = SWEAbstractSimpleComponent, + private = list( + xmlElement = "CategoryRange", + xmlNamespacePrefix = "SWE" + ), + public = list( + + #'@field codeSpace codeSpace + codeSpace = NULL, + + #'@field constraint constraint + constraint = NULL, + + #'@field value value + value = matrix(NA_character_, 1, 2), + + #'@description Initializes an object of class \link{SWECategoryRange} + #'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML} + #'@param codeSpace codeSpace + #'@param constraint constraint + #'@param value value + #'@param updatable updatable + #'@param optional optional + #'@param definition definition + initialize = function(xml = NULL, + codeSpace = 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$setCodeSpace(codeSpace) + self$setConstraint(constraint) + self$setValue(value) + } + }, + + #'@description setCodeSpace + #'@param codeSpace codeSpace + setCodeSpace = function(codeSpace){ + self$codeSpace <- codeSpace + }, + + #'@description setConstraint + #'@param constraint constraint + setConstraint = function(constraint){ + self$constraint <- constraint + }, + + #'@description setValue + #'@param value value + setValue = function(value){ + if(!is.character(value)){ + stop("Values should be character") + } + 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 + } + ) +) \ No newline at end of file diff --git a/README.md b/README.md index 5b40d976..9e6f119e 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/-20%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 6| 24| +|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-23%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 7| 23| diff --git a/inst/extdata/coverage/geometa_coverage_inventory.csv b/inst/extdata/coverage/geometa_coverage_inventory.csv index 438dbc81..e6fa06ff 100644 --- a/inst/extdata/coverage/geometa_coverage_inventory.csv +++ b/inst/extdata/coverage/geometa_coverage_inventory.csv @@ -484,7 +484,7 @@ "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","BinaryEncoding","",FALSE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Block","",FALSE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Category","",FALSE -"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","CategoryRange","",FALSE +"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","CategoryRange","SWECategoryRange",TRUE "SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","Component","",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","CountRange","",FALSE diff --git a/inst/extdata/coverage/geometa_coverage_summary.csv b/inst/extdata/coverage/geometa_coverage_summary.csv index a326662d..78c1d6b9 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",6,24,20 +"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE",7,23,23.33 diff --git a/inst/extdata/coverage/geometa_coverage_summary.md b/inst/extdata/coverage/geometa_coverage_summary.md index 616c29f1..d551ad98 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/-20%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 6| 24| +|SWE 2.0 |Sensor Web Enablement (SWE) Common Data Model |SWE |[![SWE 2.0](https://img.shields.io/badge/-23%25-ff0c0c.svg)](https://github.com/eblondel/geometa) | 7| 23| diff --git a/man/SWECategoryRange.Rd b/man/SWECategoryRange.Rd new file mode 100644 index 00000000..ed871c19 --- /dev/null +++ b/man/SWECategoryRange.Rd @@ -0,0 +1,54 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/SWECategoryRange.R +\docType{class} +\name{SWECategoryRange} +\alias{SWECategoryRange} +\title{SWECategoryRange} +\format{ +\code{\link{R6Class}} object. +} +\arguments{ +\item{xml}{object of class \link{XMLInternalNode-class} from \pkg{XML}} + +\item{updatable}{updatable} + +\item{optional}{optional} + +\item{definition}{definition} + +\item{codeSpace}{codeSpace} + +\item{constraint}{constraint} + +\item{value}{value} +} +\value{ +Object of \code{\link{R6Class}} for modelling an SWE CategoryRange +} +\description{ +Initializes an object of class \link{SWECategoryRange} + +setCodeSpace + +setConstraint + +setValue +} +\section{Fields}{ + +\describe{ +\item{\code{codeSpace}}{codeSpace} + +\item{\code{constraint}}{constraint} + +\item{\code{value}}{value} +}} + +\references{ +OGC Geography Markup Language. https://www.ogc.org/standards/swecommon +} +\author{ +Emmanuel Blondel +} +\keyword{ISO} +\keyword{SWE} diff --git a/tests/testthat/test_SWECategoryRange.R b/tests/testthat/test_SWECategoryRange.R new file mode 100644 index 00000000..e0ffeb1e --- /dev/null +++ b/tests/testthat/test_SWECategoryRange.R @@ -0,0 +1,23 @@ +# test_SWECategoryRange.R +# Author: Emmanuel Blondel +# +# Description: Unit tests for classes inheriting SWECategoryRange.R +#======================= +require(geometa, quietly = TRUE) +require(sf) +require(testthat) + +context("SWECategoryRange") + +test_that("SWECategoryRange",{ + testthat::skip_on_cran() + #encoding + cr <- SWECategoryRange$new(value = matrix(c("string1","string2"),1,2)) + xml <- cr$encode() + expect_is(xml, "XMLInternalNode") + #decoding + cr2 <- SWECategoryRange$new(xml = xml) + xml2 <- cr2$encode() + #assert object identity + expect_true(ISOAbstractObject$compare(cr, cr2)) +})