Skip to content

Commit

Permalink
#187 SWE TimeRange
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Oct 2, 2022
1 parent 2ed9069 commit 5d9a5fa
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: geometa
Type: Package
Title: Tools for Reading and Writing ISO/OGC Geographic Metadata
Version: 0.7-1
Date: 2022-09-29
Date: 2022-10-02
Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-5870-5762")))
Maintainer: Emmanuel Blondel <[email protected]>
Description: Provides facilities to handle reading and writing of geographic metadata
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export(SWEQuantity)
export(SWEQuantityRange)
export(SWEText)
export(SWETime)
export(SWETimeRange)
export(cacheISOClasses)
export(convert_metadata)
export(geometaLogger)
Expand Down
18 changes: 8 additions & 10 deletions R/SWEAbstractDataComponent.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ SWEAbstractDataComponent <- R6Class("SWEAbstractDataComponent",
xmlNamespacePrefix = "SWE"
),
public = list(
#'@field definition definition
definition = NULL,
#'@field description description
description = NULL,
#'@field label label
Expand All @@ -46,16 +44,16 @@ SWEAbstractDataComponent <- R6Class("SWEAbstractDataComponent",
if(!is.null(definition)) self$setAttr("definition", definition)
},

#'@description Set definition
#'@param definition definition
setDefinition = function(definition){
self$definition <- definition
},

#'@description Set description
#'@param description description
setDescription = function(description){
self$description <- description
self$description <- SWEElement$create(element = "description", value = description)
},

#'@description Set label
#'@param label label
setLabel = function(label){
self$label <- SWEElement$create(element = "label", value = label)
},

#'@description Adds name
Expand All @@ -77,7 +75,7 @@ SWEAbstractDataComponent <- R6Class("SWEAbstractDataComponent",
#'@description Set identifier
#'@param identifier identifier
setIdentifier = function(identifier){
self$identifier <- identifier
self$identifier <- SWEElement$create(element = "identifier", value = identifier)
}
)
)
74 changes: 74 additions & 0 deletions R/SWETimeRange.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#' SWETimeRange
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' @keywords ISO SWE
#' @return Object of \code{\link{R6Class}} for modelling an SWE Time Range
#' @format \code{\link{R6Class}} object.
#'
#' @references
#' SWE Common Data Model Encoding Standard. https://www.ogc.org/standards/swecommon
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
SWETimeRange <- R6Class("SWETimeRange",
inherit = SWEAbstractSimpleComponent,
private = list(
xmlElement = "TimeRange",
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{SWETimeRange}
#'@param xml object of class \link{XMLInternalNode-class} from \pkg{XML}
#'@param uom uom
#'@param constraint constraint
#'@param start start time
#'@param end end time
#'@param updatable updatable
#'@param optional optional
#'@param definition definition
initialize = function(xml = NULL,
uom = NULL, constraint = NULL, start = NULL, end = NULL,
updatable = NULL, optional = FALSE, definition = NULL){
super$initialize(xml, element = private$xmlElement,
updatable = updatable, optional = optional, definition = definition)
if(is.null(xml)){
self$setUom(uom)
self$setConstraint(constraint)
self$setValue(start = start, end = end)
}
},

#'@description setUom
#'@param uom uom
setUom = function(uom){
uomElem <- SWEElement$create(element = "uom")
uomElem$setAttr("code", uom)
self$uom <- uomElem
},

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

#'@description setValue
#'@param start start time
#'@param end end time
setValue = function(start, end){
self$value <- matrix(list(start, end), nrow = 1, ncol = 2, byrow = TRUE)
}
)
)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +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/-47%25-f9ae2c.svg)](https://github.com/eblondel/geometa) | 14| 16|

|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|
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 @@ -499,6 +499,6 @@
"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","SWETime",TRUE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","TimeRange","<missing>",FALSE
"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","<missing>",FALSE
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE","XMLEncoding","<missing>",FALSE
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",14,16,46.67
"SWE 2.0","Sensor Web Enablement (SWE) Common Data Model","SWE",15,15,50
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/-47%25-f9ae2c.svg)](https://github.com/eblondel/geometa) | 14| 16|
|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|
54 changes: 54 additions & 0 deletions man/SWETimeRange.Rd

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

25 changes: 25 additions & 0 deletions tests/testthat/test_SWETimeRange.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# test_SWETimeRange.R
# Author: Emmanuel Blondel <[email protected]>
#
# Description: Unit tests for classes inheriting SWETimeRange.R
#=======================
require(geometa, quietly = TRUE)
require(sf)
require(testthat)

context("SWETimeRange")

test_that("SWETimeRange",{
testthat::skip_on_cran()
#encoding
time <- SWETimeRange$new()
time$setValue(start = Sys.time(), end = Sys.time()+3600)
time$setAttr("definition", "http://mmisw.org/ont/ioos/swe_element_type/observationTimeRange")
xml <- time$encode() #TODO check how to rencode properly as ISO 8601 datetimes
expect_is(xml, "XMLInternalNode")
#decoding
time2 <- SWETimeRange$new(xml = xml)
xml2 <- time2$encode()
#assert object identity
expect_true(ISOAbstractObject$compare(time, time2))
})

0 comments on commit 5d9a5fa

Please sign in to comment.