Skip to content

Commit

Permalink
#69 GMLParameterValue, GMLParameterValueGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 28, 2018
1 parent 1281e8b commit e8273ce
Show file tree
Hide file tree
Showing 11 changed files with 584 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(GMLAbstractGML)
export(GMLAbstractGeneralConversion)
export(GMLAbstractGeneralDerivedCRS)
export(GMLAbstractGeneralOperationParameter)
export(GMLAbstractGeneralParameterValue)
export(GMLAbstractGeometricAggregate)
export(GMLAbstractGeometricPrimitive)
export(GMLAbstractGeometry)
Expand Down Expand Up @@ -42,6 +43,8 @@ export(GMLObliqueCartesianCS)
export(GMLOperationMethod)
export(GMLOperationParameter)
export(GMLOperationParameterGroup)
export(GMLParameterValue)
export(GMLParameterValueGroup)
export(GMLPoint)
export(GMLPolarCS)
export(GMLPolygon)
Expand Down
39 changes: 39 additions & 0 deletions R/GMLAbstractGeneralParameterValue.R
Original file line number Diff line number Diff line change
@@ -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 <emmanuel.blondel1@@gmail.com>
#'
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)
}
)
)
2 changes: 1 addition & 1 deletion R/GMLElement.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
125 changes: 125 additions & 0 deletions R/GMLParameterValue.R
Original file line number Diff line number Diff line change
@@ -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 <emmanuel.blondel1@@gmail.com>
#'
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
}
)
)
77 changes: 77 additions & 0 deletions R/GMLParameterValueGroup.R
Original file line number Diff line number Diff line change
@@ -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 <emmanuel.blondel1@@gmail.com>
#'
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
}
)
)
1 change: 1 addition & 0 deletions R/ISOAbstractObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
41 changes: 41 additions & 0 deletions man/GMLAbstractGeneralParameterValue.Rd

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

Loading

0 comments on commit e8273ce

Please sign in to comment.