From e8273cec329bbaad853d0e002bb455853dab9f4b Mon Sep 17 00:00:00 2001 From: eblondel Date: Sun, 28 Jan 2018 23:13:27 +0100 Subject: [PATCH] #69 GMLParameterValue, GMLParameterValueGroup --- NAMESPACE | 3 + R/GMLAbstractGeneralParameterValue.R | 39 ++++++ R/GMLElement.R | 2 +- R/GMLParameterValue.R | 125 +++++++++++++++++++ R/GMLParameterValueGroup.R | 77 ++++++++++++ R/ISOAbstractObject.R | 1 + man/GMLAbstractGeneralParameterValue.Rd | 41 ++++++ man/GMLParameterValue.Rd | 75 +++++++++++ man/GMLParameterValueGroup.Rd | 58 +++++++++ tests/testthat/test_GMLParameterValue.R | 110 ++++++++++++++++ tests/testthat/test_GMLParameterValueGroup.R | 54 ++++++++ 11 files changed, 584 insertions(+), 1 deletion(-) create mode 100644 R/GMLAbstractGeneralParameterValue.R create mode 100644 R/GMLParameterValue.R create mode 100644 R/GMLParameterValueGroup.R create mode 100644 man/GMLAbstractGeneralParameterValue.Rd create mode 100644 man/GMLParameterValue.Rd create mode 100644 man/GMLParameterValueGroup.Rd create mode 100644 tests/testthat/test_GMLParameterValue.R create mode 100644 tests/testthat/test_GMLParameterValueGroup.R diff --git a/NAMESPACE b/NAMESPACE index 9d4395d3..8effe2f9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(GMLAbstractGML) export(GMLAbstractGeneralConversion) export(GMLAbstractGeneralDerivedCRS) export(GMLAbstractGeneralOperationParameter) +export(GMLAbstractGeneralParameterValue) export(GMLAbstractGeometricAggregate) export(GMLAbstractGeometricPrimitive) export(GMLAbstractGeometry) @@ -42,6 +43,8 @@ export(GMLObliqueCartesianCS) export(GMLOperationMethod) export(GMLOperationParameter) export(GMLOperationParameterGroup) +export(GMLParameterValue) +export(GMLParameterValueGroup) export(GMLPoint) export(GMLPolarCS) export(GMLPolygon) diff --git a/R/GMLAbstractGeneralParameterValue.R b/R/GMLAbstractGeneralParameterValue.R new file mode 100644 index 00000000..7a04710f --- /dev/null +++ b/R/GMLAbstractGeneralParameterValue.R @@ -0,0 +1,39 @@ +#' GMLAbstractGeneralParameterValue +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO GML Abstract GeneralParameterValue +#' @return Object of \code{\link{R6Class}} for modelling an GML abstract general ParameterValue +#' @format \code{\link{R6Class}} object. +#' +#' @section Methods: +#' \describe{ +#' \item{\code{new(xml, element, attrs, defaults)}}{ +#' This method is used to instantiate a GML abstract GML +#' } +#' } +#' +#' @note Class used internally by geometa +#' +#' @references +#' ISO 19136:2007 Geographic Information -- Geographic Markup Language. +#' http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554 +#' +#' OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml +#' +#' @author Emmanuel Blondel +#' +GMLAbstractGeneralParameterValue <- R6Class("GMLAbstractGeneralParameterValue", + inherit = GMLAbstractObject, + private = list( + xmlElement = "AbstractGeneralParameterValue", + xmlNamespacePrefix = "GML" + ), + public = list( + initialize = function(xml = NULL, element = NULL, attrs = list(), defaults = list()){ + if(is.null(element)) element <- private$xmlElement + super$initialize(xml, element = element, attrs = attrs, defaults = defaults, wrap = TRUE) + } + ) +) \ No newline at end of file diff --git a/R/GMLElement.R b/R/GMLElement.R index ba226b94..d1f97a9f 100644 --- a/R/GMLElement.R +++ b/R/GMLElement.R @@ -45,10 +45,10 @@ GMLElement <- R6Class("GMLElement", #set attrs if any self$attrs <- as.list(xmlAttrs(xml, TRUE, FALSE)) - fieldValue <- xmlValue(xml, recursive = FALSE) if(length(fieldValue)>0){ #set value if any + if(fieldValue %in% c("true","false")) fieldValue <- as.logical(fieldValue) fieldValue <- private$toComplexTypes(fieldValue) if(!is.na(fieldValue)) self$setValue(fieldValue) }else{ diff --git a/R/GMLParameterValue.R b/R/GMLParameterValue.R new file mode 100644 index 00000000..9af4a023 --- /dev/null +++ b/R/GMLParameterValue.R @@ -0,0 +1,125 @@ +#' GMLParameterValue +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO GML parameter value +#' @return Object of \code{\link{R6Class}} for modelling an GML parameter value +#' @format \code{\link{R6Class}} object. +#' +#' @field value +#' @field operationParameter +#' +#' @section Methods: +#' \describe{ +#' \item{\code{new(xml, defaults)}}{ +#' This method is used to instantiate a GML ParameterValue +#' } +#' \item{\code{setValue(value,uom)}}{ +#' Sets the value (object of class "numeric"), with unit of measure (uom) +#' } +#' \item{\code{setStringValue(value)}}{ +#' Sets a string value +#' } +#' \item{\code{setIntegerValue(value)}}{ +#' Sets an integer value +#' } +#' \item{\code{setBooleanValue(value)}}{ +#' Sets a boolean value +#' } +#' \item{\code{setValueFile(value)}}{ +#' Sets a file value +#' } +#' \item{\code{setOperationParameter(operationParameter)}}{ +#' Sets the operation parameter, object of class \code{GMLOperationParameter} +#' } +#' } +#' +#' @examples +#' gml <- GMLParameterValue$new() +#' gml$setValue(1.1, "test") +#' op <- GMLOperationParameter$new() +#' op$setDescriptionReference("someref") +#' op$setIdentifier("identifier", "codespace") +#' op$addName("name1", "codespace") +#' op$addName("name2", "codespace") +#' op$setMinimumOccurs(2L) +#' gml$setOperationParameter(op) +#' xml <- gml$encode() +#' +#' @references +#' ISO 19136:2007 Geographic Information -- Geographic Markup Language. +#' http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554 +#' +#' OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml +#' +#' @author Emmanuel Blondel +#' +GMLParameterValue <- R6Class("GMLParameterValue", + inherit = GMLAbstractGeneralParameterValue, + private = list( + xmlElement = "ParameterValue", + xmlNamespacePrefix = "GML" + ), + public = list( + value = NULL, + stringValue = NULL, + integerValue = NULL, + booleanValue = NULL, + valueList = NULL, #TODO + integerValueList = NULL, #TODO + valueFile = NULL, + operationParameter = NULL, + initialize = function(xml = NULL, defaults = list()){ + super$initialize(xml, element = private$xmlElement, defaults) + }, + + #setValue + setValue = function(value, uom){ + if(!is(value, "numeric")){stop("Value should be an object of class 'numeric'")} + valueElem <- GMLElement$new(element = "value") + valueElem$setValue(value) + valueElem$attrs <- list(uom = uom) + self$value <- valueElem + }, + + #setStringValue + setStringValue = function(value){ + valueElem <- GMLElement$new(element = "stringValue") + valueElem$setValue(value) + self$stringValue <- valueElem + }, + + #setIntegerValue + setIntegerValue = function(value){ + if(!is(value, "integer")){stop("Value should be an object of class 'integer'")} + valueElem <- GMLElement$new(element = "integerValue") + valueElem$setValue(value) + self$integerValue <- valueElem + }, + + #setBooleanValue + setBooleanValue = function(value){ + if(!is(value, "logical")){stop("Value should be an object of class 'logical'")} + valueElem <- GMLElement$new(element = "booleanValue") + valueElem$setValue(value) + self$booleanValue <- valueElem + }, + + #setValueFile + setValueFile = function(value){ + if(!is(value, "character")){stop("Value should be an object of class 'character'")} + valueElem <- GMLElement$new(element = "valueFile") + valueElem$setValue(value) + self$valueFile <- valueElem + }, + + #setOperationParameter + setOperationParameter = function(operationParameter){ + if(!is(operationParameter, "GMLOperationParameter")){ + stop("Input 'operationParameter' should be of an object oftype 'GMLOperationParameter'") + } + self$operationParameter <- operationParameter + } + ) +) \ No newline at end of file diff --git a/R/GMLParameterValueGroup.R b/R/GMLParameterValueGroup.R new file mode 100644 index 00000000..b28c88e0 --- /dev/null +++ b/R/GMLParameterValueGroup.R @@ -0,0 +1,77 @@ +#' GMLParameterValueGroup +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @keywords ISO GML parameter value group +#' @return Object of \code{\link{R6Class}} for modelling an GML parameter value group +#' @format \code{\link{R6Class}} object. +#' +#' @field parameterValue +#' @field group +#' +#' @section Methods: +#' \describe{ +#' \item{\code{new(xml, defaults)}}{ +#' This method is used to instantiate a GML ParameterValue +#' } +#' \item{\code{addParameterValue(parameterValue)}}{ +#' Adds a parameter value, object of class 'GMLParameterValue' +#' } +#' \item{\code{delParameterValue(parameterValue)}}{ +#' Deletes a parameter value, object of class 'GMLParameterValue' +#' } +#' \item{\code{setOperationParameterGroup(operationParameterGroup)}}{ +#' Sets the operation parameter group, object of class \code{GMLOperationParameterGroup} +#' } +#' } +#' +#' @examples +#' gml <- GMLParameterValueGroup$new() +#' +#' @references +#' ISO 19136:2007 Geographic Information -- Geographic Markup Language. +#' http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554 +#' +#' OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml +#' +#' @author Emmanuel Blondel +#' +GMLParameterValueGroup <- R6Class("GMLParameterValueGroup", + inherit = GMLAbstractGeneralParameterValue, + private = list( + xmlElement = "ParameterValueGroup", + xmlNamespacePrefix = "GML" + ), + public = list( + parameterValue = list(), + group = NULL, + initialize = function(xml = NULL, defaults = list()){ + super$initialize(xml, element = private$xmlElement, defaults) + }, + + #addParameterValue + addParameterValue = function(parameterValue){ + if(!is(parameterValue, "GMLParameterValue")){ + stop("Input should be an object of class 'GMLParameterValue") + } + return(self$addListElement("parameterValue", parameterValue)) + }, + + #delParameterValue + delParameterValue = function(parameterValue){ + if(!is(parameterValue, "GMLParameterValue")){ + stop("Input should be an object of class 'GMLParameterValue") + } + return(self$delListElement("parameterValue", parameterValue)) + }, + + #setOperationParameterGroup + setOperationParameterGroup = function(operationParameterGroup){ + if(!is(operationParameterGroup, "GMLOperationParameterGroup")){ + stop("Input 'operationParameterGroup' should be of an object oftype 'GMLOperationParameterGroup'") + } + self$group <- operationParameterGroup + } + ) +) \ No newline at end of file diff --git a/R/ISOAbstractObject.R b/R/ISOAbstractObject.R index 21e3787c..896823d2 100644 --- a/R/ISOAbstractObject.R +++ b/R/ISOAbstractObject.R @@ -545,6 +545,7 @@ ISOAbstractObject <- R6Class("ISOAbstractObject", rootXML$addNode(emptyNode$value()) }else{ if(field == "value"){ + if(is.logical(fieldObj)) fieldObj <- tolower(as.character(is.logical(fieldObj))) fieldObj <- private$fromComplexTypes(fieldObj) rootXML$addNode(xmlTextNode(fieldObj)) }else{ diff --git a/man/GMLAbstractGeneralParameterValue.Rd b/man/GMLAbstractGeneralParameterValue.Rd new file mode 100644 index 00000000..e97bb1df --- /dev/null +++ b/man/GMLAbstractGeneralParameterValue.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/GMLAbstractGeneralParameterValue.R +\docType{class} +\name{GMLAbstractGeneralParameterValue} +\alias{GMLAbstractGeneralParameterValue} +\title{GMLAbstractGeneralParameterValue} +\format{\code{\link{R6Class}} object.} +\usage{ +GMLAbstractGeneralParameterValue +} +\value{ +Object of \code{\link{R6Class}} for modelling an GML abstract general ParameterValue +} +\description{ +GMLAbstractGeneralParameterValue +} +\note{ +Class used internally by geometa +} +\section{Methods}{ + +\describe{ + \item{\code{new(xml, element, attrs, defaults)}}{ + This method is used to instantiate a GML abstract GML + } +} +} + +\references{ +ISO 19136:2007 Geographic Information -- Geographic Markup Language. + http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554 + + OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml +} +\author{ +Emmanuel Blondel +} +\keyword{Abstract} +\keyword{GML} +\keyword{GeneralParameterValue} +\keyword{ISO} diff --git a/man/GMLParameterValue.Rd b/man/GMLParameterValue.Rd new file mode 100644 index 00000000..794a8a22 --- /dev/null +++ b/man/GMLParameterValue.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/GMLParameterValue.R +\docType{class} +\name{GMLParameterValue} +\alias{GMLParameterValue} +\title{GMLParameterValue} +\format{\code{\link{R6Class}} object.} +\usage{ +GMLParameterValue +} +\value{ +Object of \code{\link{R6Class}} for modelling an GML parameter value +} +\description{ +GMLParameterValue +} +\section{Fields}{ + +\describe{ +\item{\code{operationParameter}}{} +}} + +\section{Methods}{ + +\describe{ + \item{\code{new(xml, defaults)}}{ + This method is used to instantiate a GML ParameterValue + } + \item{\code{setValue(value,uom)}}{ + Sets the value (object of class "numeric"), with unit of measure (uom) + } + \item{\code{setStringValue(value)}}{ + Sets a string value + } + \item{\code{setIntegerValue(value)}}{ + Sets an integer value + } + \item{\code{setBooleanValue(value)}}{ + Sets a boolean value + } + \item{\code{setValueFile(value)}}{ + Sets a file value + } + \item{\code{setOperationParameter(operationParameter)}}{ + Sets the operation parameter, object of class \code{GMLOperationParameter} + } +} +} + +\examples{ + gml <- GMLParameterValue$new() + gml$setValue(1.1, "test") + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + gml$setOperationParameter(op) + xml <- gml$encode() + +} +\references{ +ISO 19136:2007 Geographic Information -- Geographic Markup Language. + http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554 + + OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml +} +\author{ +Emmanuel Blondel +} +\keyword{GML} +\keyword{ISO} +\keyword{parameter} +\keyword{value} diff --git a/man/GMLParameterValueGroup.Rd b/man/GMLParameterValueGroup.Rd new file mode 100644 index 00000000..c3f9e4e1 --- /dev/null +++ b/man/GMLParameterValueGroup.Rd @@ -0,0 +1,58 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/GMLParameterValueGroup.R +\docType{class} +\name{GMLParameterValueGroup} +\alias{GMLParameterValueGroup} +\title{GMLParameterValueGroup} +\format{\code{\link{R6Class}} object.} +\usage{ +GMLParameterValueGroup +} +\value{ +Object of \code{\link{R6Class}} for modelling an GML parameter value group +} +\description{ +GMLParameterValueGroup +} +\section{Fields}{ + +\describe{ +\item{\code{group}}{} +}} + +\section{Methods}{ + +\describe{ + \item{\code{new(xml, defaults)}}{ + This method is used to instantiate a GML ParameterValue + } + \item{\code{addParameterValue(parameterValue)}}{ + Adds a parameter value, object of class 'GMLParameterValue' + } + \item{\code{delParameterValue(parameterValue)}}{ + Deletes a parameter value, object of class 'GMLParameterValue' + } + \item{\code{setOperationParameterGroup(operationParameterGroup)}}{ + Sets the operation parameter group, object of class \code{GMLOperationParameterGroup} + } +} +} + +\examples{ + gml <- GMLParameterValueGroup$new() + +} +\references{ +ISO 19136:2007 Geographic Information -- Geographic Markup Language. + http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=32554 + + OGC Geography Markup Language. http://www.opengeospatial.org/standards/gml +} +\author{ +Emmanuel Blondel +} +\keyword{GML} +\keyword{ISO} +\keyword{group} +\keyword{parameter} +\keyword{value} diff --git a/tests/testthat/test_GMLParameterValue.R b/tests/testthat/test_GMLParameterValue.R new file mode 100644 index 00000000..f50f02ea --- /dev/null +++ b/tests/testthat/test_GMLParameterValue.R @@ -0,0 +1,110 @@ +# test_GMLParameterValue.R +# Author: Emmanuel Blondel +# +# Description: Unit tests for GMLParameterValue.R +#======================= +require(geometa, quietly = TRUE) +require(testthat) +require(XML) + +context("GMLParameter") + +test_that("encoding - value",{ + #encoding + gml <- GMLParameterValue$new() + gml$setValue(1.1, "test") + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + gml$setOperationParameter(op) + xml <- gml$encode() + expect_is(xml, "XMLInternalNode") + #decoding + gml2 <- GMLParameterValue$new(xml = xml) + xml2 <- gml2$encode() + #object identity + expect_true(ISOAbstractObject$compare(gml, gml2)) +}) + +test_that("encoding - stringValue",{ + #encoding + gml <- GMLParameterValue$new() + gml$setStringValue("test") + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + gml$setOperationParameter(op) + xml <- gml$encode() + expect_is(xml, "XMLInternalNode") + #decoding + gml2 <- GMLParameterValue$new(xml = xml) + xml2 <- gml2$encode() + #object identity + expect_true(ISOAbstractObject$compare(gml, gml2)) +}) + +test_that("encoding - integerValue",{ + #encoding + gml <- GMLParameterValue$new() + gml$setIntegerValue(1L) + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + gml$setOperationParameter(op) + xml <- gml$encode() + expect_is(xml, "XMLInternalNode") + #decoding + gml2 <- GMLParameterValue$new(xml = xml) + xml2 <- gml2$encode() + #object identity + expect_true(ISOAbstractObject$compare(gml, gml2)) +}) + +test_that("encoding - booleanValue",{ + #encoding + gml <- GMLParameterValue$new() + gml$setBooleanValue(TRUE) + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + gml$setOperationParameter(op) + xml <- gml$encode() + expect_is(xml, "XMLInternalNode") + #decoding + gml2 <- GMLParameterValue$new(xml = xml) + xml2 <- gml2$encode() + #object identity + expect_true(ISOAbstractObject$compare(gml, gml2)) +}) + +test_that("encoding - valueFile",{ + #encoding + gml <- GMLParameterValue$new() + gml$setValueFile("http://somelink") + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + gml$setOperationParameter(op) + xml <- gml$encode() + expect_is(xml, "XMLInternalNode") + #decoding + gml2 <- GMLParameterValue$new(xml = xml) + xml2 <- gml2$encode() + #object identity + expect_true(ISOAbstractObject$compare(gml, gml2)) +}) diff --git a/tests/testthat/test_GMLParameterValueGroup.R b/tests/testthat/test_GMLParameterValueGroup.R new file mode 100644 index 00000000..7fff54c8 --- /dev/null +++ b/tests/testthat/test_GMLParameterValueGroup.R @@ -0,0 +1,54 @@ +# test_GMLParameterValueGroup.R +# Author: Emmanuel Blondel +# +# Description: Unit tests for GMLParameterValueGroup.R +#======================= +require(geometa, quietly = TRUE) +require(testthat) +require(XML) + +context("GMLParameterGroup") + +test_that("encoding",{ + #encoding + pv1 <- GMLParameterValue$new() + pv1$setValue(1.0, "m") + op <- GMLOperationParameter$new() + op$setDescriptionReference("someref") + op$setIdentifier("identifier", "codespace") + op$addName("name1", "codespace") + op$addName("name2", "codespace") + op$setMinimumOccurs(2L) + pv1$setOperationParameter(op) + + pv2 <- GMLParameterValue$new() + pv2$setValue(2.0, "m") + op2 <- GMLOperationParameter$new() + op2$setDescriptionReference("someref") + op2$setIdentifier("identifier", "codespace") + op2$addName("name1", "codespace") + op2$addName("name2", "codespace") + op2$setMinimumOccurs(2L) + pv2$setOperationParameter(op2) + + gml <- GMLParameterValueGroup$new() + gml$addParameterValue(pv1) + gml$addParameterValue(pv2) + + opg <- GMLOperationParameterGroup$new() + opg$setDescriptionReference("someref") + opg$setIdentifier("identifier", "codespace") + opg$addName("name1", "codespace") + opg$addName("name2", "codespace") + opg$setMinimumOccurs(2L) + opg$setMaximumOccurs(4L) + gml$setOperationParameterGroup(opg) + + xml <- gml$encode() + expect_is(xml, "XMLInternalNode") + #decoding + gml2 <- GMLParameterValueGroup$new(xml = xml) + xml2 <- gml2$encode() + #object identity + expect_true(ISOAbstractObject$compare(gml, gml2)) +}) \ No newline at end of file