Skip to content

Commit

Permalink
#69 more work on GMLConversion
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 29, 2018
1 parent e8273ce commit 2997042
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 15 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.3-0
Date: 2018-01-22
Date: 2018-01-29
Author: Emmanuel Blondel <[email protected]>
Maintainer: Emmanuel Blondel <[email protected]>
Description: Provides facilities to handle reading and writing of geographic metadata
Expand Down
30 changes: 29 additions & 1 deletion R/GMLAbstractCoordinateOperation.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
#' \item{\code{new(xml, defaults, id)}}{
#' This method is used to instantiate a GML Abstract CRS
#' }
#' \item{\code{setDomainOfValidity(domainOfValidity)}}{
#' Sets the domain of validity
#' }
#' \item{\code{addScope(scope)}}{
#' Adds a scope
#' }
#' \item{\code{delScope(scope)}}{
#' Deletes a scope
#' }
#' \item{\code{setVersion(version)}}{
#' Sets version
#' }
Expand Down Expand Up @@ -49,7 +58,10 @@ GMLAbstractCoordinateOperation <- R6Class("GMLAbstractCoordinateOperation",
xmlNamespacePrefix = "GML"
),
public = list(

#+ domainOfValidity [0..1]: character
domainOfValidity = NULL,
#+ scope [1..*]: character
scope = list(),
#+ operationVersion [0..1]: character
operationVersion = NULL,
#+ coordinateOperationAccuracy [0..1]: ISOPositionalAccuracy
Expand All @@ -66,6 +78,22 @@ GMLAbstractCoordinateOperation <- R6Class("GMLAbstractCoordinateOperation",
}
},

#setDomainOfValidity
setDomainOfValidity = function(domainOfValidity){
if(!is(domainOfValidity, "ISOExtent")) stop("Input should be an object of class 'ISOExtent'")
self$domainOfValidity <- domainOfValidity
},

#addScope
addScope = function(scope){
return(self$addListElement("scope", GMLElement$create("scope", value = scope)))
},

#delScope
delScope = function(scope){
return(self$delListElement("scope", GMLElement$create("scope", value = scope)))
},

#setVersion
setVersion = function(version){
self$operationVersion <- GMLElement$create("operationVersion", value = version)
Expand Down
12 changes: 6 additions & 6 deletions R/GMLConversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ GMLConversion <- R6Class("GMLConversion",

#addParameterValue
addParameterValue = function(paramValue){
if(!is(paramValue, "GMLParameterValue")){
stop("The argument value should be an object of class 'GMLParameterValue'")
if(!inherits(paramValue, "GMLAbstractGeneralParameterValue")){
stop("The argument value should be an object of class 'GMLParameterValue' or 'GMLParameterValueGroup'")
}
return(self$addListElement("parameterValue", GMLElement$create("parameterValue", value = paramValue)))
return(self$addListElement("parameterValue", paramValue))
},

#delParameterValue
delParameterValue = function(paramValue){
if(!is(paramValue, "GMLParameterValue")){
stop("The argument value should be an object of class 'GMLParameterValue'")
if(!inherits(paramValue, "GMLAbstractGeneralParameterValue")){
stop("The argument value should be an object of class 'GMLParameterValue' or 'GMLParameterValueGroup'")
}
return(self$delListElement("parameterValue", GMLElement$create("parameterValue", value = paramValue)))
return(self$delListElement("parameterValue", paramValue))
}

)
Expand Down
23 changes: 19 additions & 4 deletions R/GMLOperationMethod.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#' @format \code{\link{R6Class}} object.
#'
#' @field formulaCitation
#' @field formula
#' @field sourceDimensions
#' @field targetDimensions
#' @field parameter
#'
#' @section Inherited methods:
#' \describe{
Expand All @@ -24,6 +26,9 @@
#' \item{\code{setFormulaCitation(citation)}}{
#' Sets the formula citation, object of class \code{ISOCitation}
#' }
#' \item{\code{setFormula(formula)}}{
#' Sets a formula, object of class \code{character}
#' }
#' \item{\code{setSourceDimensions(value)}}{
#' Sets the number of source dimensions, object of class \code{integer}
#' }
Expand Down Expand Up @@ -56,8 +61,10 @@ GMLOperationMethod <- R6Class("GMLOperationMethod",
),
public = list(

#+ formulaCitation [1..1]: ISOCitation
#+ formulaCitation [1..1]: ISOCitation, or use forula
formulaCitation = NA,
#+ formula [1..1]: character
formula = NULL,
#+ sourceDimensions [0..1]: integer
sourceDimensions = NULL,
#+ targetDimensions [0..1]: integer
Expand All @@ -70,7 +77,15 @@ GMLOperationMethod <- R6Class("GMLOperationMethod",
if(!is(citation, "ISOCitation")){
stop("The argument value should be an object of class 'ISOCitation'")
}
self$formulaCitation <- GMLElement$create("formulaCitation", value = citation)
self$formulaCitation <- citation
},

#setFormula
setFormula = function(formula){
if(!is(formula, "character")) stop("Input object should be of class 'character'")
formulaElem <- GMLElement$new(element = "formula")
formulaElem$setValue(formula)
self$formula <- formulaElem
},

#setSourceDimensions
Expand Down Expand Up @@ -100,15 +115,15 @@ GMLOperationMethod <- R6Class("GMLOperationMethod",
if(!inherits(param, "GMLAbstractGeneralOperationParameter")){
stop("The argument value should be an object of class 'GMLOperationParameter' or 'GMLOperationParameterGroup'")
}
return(self$addListElement("parameter", GMLElement$create("parameter", value = param)))
return(self$addListElement("parameter", param))
},

#delParameter
delParameter = function(param){
if(!inherits(param, "GMLAbstractGeneralOperationParameter")){
stop("The argument value should be an object of class 'GMLOperationParameter' or 'GMLOperationParameterGroup'")
}
return(self$delListElement("parameter", GMLElement$create("parameter", value = param)))
return(self$delListElement("parameter", param))
}

)
Expand Down
2 changes: 1 addition & 1 deletion R/geometa.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' Package: \tab geometa\cr
#' Type: \tab Package\cr
#' Version: \tab 0.3-0\cr
#' Date: \tab 2018-01-22\cr
#' Date: \tab 2018-01-29\cr
#' License: \tab MIT\cr
#' LazyLoad: \tab yes\cr
#' }
Expand Down
9 changes: 9 additions & 0 deletions man/GMLAbstractCoordinateOperation.Rd

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

5 changes: 4 additions & 1 deletion man/GMLOperationMethod.Rd

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

2 changes: 1 addition & 1 deletion man/geometa.Rd

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

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

context("GMLConversion")

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)

pvg <- GMLParameterValueGroup$new()
pvg$addParameterValue(pv1)
pvg$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)
pvg$setOperationParameterGroup(opg)

gml <- GMLConversion$new()
gml$addParameterValue(pvg)

method <- GMLOperationMethod$new()
method$setIdentifier("method","codespace")
method$setSourceDimensions(1)
method$setTargetDimensions(1)

cit <- ISOCitation$new()
cit$setTitle("sometitle")
d <- ISODate$new()
d$setDate(ISOdate(2015, 1, 1, 1))
d$setDateType("publication")
cit$addDate(d)
expect_error(cit$addDate("wrong date type"))
cit$setEdition("1.0")
cit$setEditionDate(ISOdate(2015, 1, 1, 1))
expect_error(cit$setEditionDate("wrong date type"))
cit$setIdentifier(ISOMetaIdentifier$new(code = "identifier"))
expect_error(cit$setIdentifier("wrong identifier type"))
cit$setPresentationForm("mapDigital")

#adding a cited responsible party
rp <- ISOResponsibleParty$new()
rp$setIndividualName("someone")
rp$setOrganisationName("somewhere")
rp$setPositionName("someposition")
rp$setRole("pointOfContact")
contact <- ISOContact$new()
phone <- ISOTelephone$new()
phone$setVoice("myphonenumber")
phone$setFacsimile("myfacsimile")
contact$setPhone(phone)
address <- ISOAddress$new()
address$setDeliveryPoint("theaddress")
address$setCity("thecity")
address$setPostalCode("111")
address$setCountry("France")
address$setEmail("[email protected]")
contact$setAddress(address)
res <- ISOOnlineResource$new()
res$setLinkage("http://www.somewhereovertheweb.org")
res$setName("somename")
contact$setOnlineResource(res)
rp$setContactInfo(contact)
cit$setCitedResponsibleParty(rp)
method$setFormulaCitation(cit)

gml$setIdentifier("conversion", "codespace")
extent <- ISOExtent$new()
bbox <- ISOGeographicBoundingBox$new(minx = -180, miny = -90, maxx = 180, maxy = 90)
extent$setGeographicElement(bbox)
gml$setDomainOfValidity(extent)
gml$addScope("scope")
xml <- gml$encode()
expect_is(xml, "XMLInternalNode")
#decoding
gml2 <- GMLConversion$new(xml = xml)
xml2 <- gml2$encode()
#object identity
expect_true(ISOAbstractObject$compare(gml, gml2))
})
66 changes: 66 additions & 0 deletions tests/testthat/test_GMLOperationMethod.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# test_GMLConversion.R
# Author: Emmanuel Blondel <[email protected]>
#
# Description: Unit tests for GMLConversion.R
#=======================
require(geometa, quietly = TRUE)
require(testthat)
require(XML)

context("GMLConversion")

test_that("encoding",{
#encoding
gml <- GMLOperationMethod$new()
gml$setIdentifier("method","codespace")
gml$setSourceDimensions(1)
gml$setTargetDimensions(1)

cit <- ISOCitation$new()
cit$setTitle("sometitle")
d <- ISODate$new()
d$setDate(ISOdate(2015, 1, 1, 1))
d$setDateType("publication")
cit$addDate(d)
expect_error(cit$addDate("wrong date type"))
cit$setEdition("1.0")
cit$setEditionDate(ISOdate(2015, 1, 1, 1))
expect_error(cit$setEditionDate("wrong date type"))
cit$setIdentifier(ISOMetaIdentifier$new(code = "identifier"))
expect_error(cit$setIdentifier("wrong identifier type"))
cit$setPresentationForm("mapDigital")

#adding a cited responsible party
rp <- ISOResponsibleParty$new()
rp$setIndividualName("someone")
rp$setOrganisationName("somewhere")
rp$setPositionName("someposition")
rp$setRole("pointOfContact")
contact <- ISOContact$new()
phone <- ISOTelephone$new()
phone$setVoice("myphonenumber")
phone$setFacsimile("myfacsimile")
contact$setPhone(phone)
address <- ISOAddress$new()
address$setDeliveryPoint("theaddress")
address$setCity("thecity")
address$setPostalCode("111")
address$setCountry("France")
address$setEmail("[email protected]")
contact$setAddress(address)
res <- ISOOnlineResource$new()
res$setLinkage("http://www.somewhereovertheweb.org")
res$setName("somename")
contact$setOnlineResource(res)
rp$setContactInfo(contact)
cit$setCitedResponsibleParty(rp)
gml$setFormulaCitation(cit)

xml <- gml$encode()
expect_is(xml, "XMLInternalNode")
#decoding
gml2 <- GMLOperationMethod$new(xml = xml)
xml2 <- gml2$encode()
#object identity
expect_true(ISOAbstractObject$compare(gml, gml2))
})

0 comments on commit 2997042

Please sign in to comment.