Skip to content

Commit

Permalink
Merge pull request #337 from wdwatkins/geojob2webdata
Browse files Browse the repository at this point in the history
deal with namespaces, XMLs with no start/end time
  • Loading branch information
Jordan S Read committed Apr 20, 2017
2 parents 9c342ea + 8aef35c commit ea70886
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
13 changes: 12 additions & 1 deletion R/01-webdata-obj.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ pkg.env$gconfig <- list('wps.url'='https://cida.usgs.gov/gdp/process/WebProcessi
'verbose' = FALSE,
'retries' = 1,
'version' = '1.0.0')
pkg.env$NAMESPACES <- c(wps = 'http://www.opengis.net/wps/1.0.0',
xsi = 'http://www.w3.org/2001/XMLSchema-instance',
xlink = 'http://www.w3.org/1999/xlink',
ogc = 'http://www.opengis.net/ogc',
ows = 'http://www.opengis.net/ows/1.1',
gml = 'http://www.opengis.net/gml',
wfs = 'http://www.opengis.net/wfs')

#' @importFrom utils lsf.str packageName
.onLoad <- function(libname, pkgname){
Expand Down Expand Up @@ -108,7 +115,11 @@ setMethod("webdata", signature("character"), function(.Object=c("prism", "iclus
setMethod("webdata", signature("geojob"), function(.Object, ...) {
xmlVals <- inputs(xmlParse(xml(.Object)))
url <- xmlVals[["DATASET_URI"]]
times <- c(xmlVals[["TIME_START"]], xmlVals[["TIME_END"]])
times <- c(start = xmlVals[["TIME_START"]], end = xmlVals[["TIME_END"]])
if(is.null(times[['start']])) {times[['start']] <- NA}
if(length(times) == 1) {times[['end']] <- NA}
times <- as.POSIXct(c(times[['start']], times[['end']])) #could get out of order with one missing

variables <- xmlVals[names(xmlVals) %in% c("OBSERVED_PROPERTY", "DATASET_ID")]
webdata <- webdata(url = url, times = times,
variables = unlist(variables), ...)
Expand Down
4 changes: 2 additions & 2 deletions R/02-webgeom-obj.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ setMethod("initialize", signature = "webgeom",
.Object@geom = geom
.Object@attribute = attribute
.Object@version = version
.Object@GML_NAMESPACE = 'http://www.opengis.net/gml'
.Object@WFS_NAMESPACE = 'http://www.opengis.net/wfs'
.Object@GML_NAMESPACE = pkg.env$NAMESPACES[['gml']]
.Object@WFS_NAMESPACE = pkg.env$NAMESPACES[['wfs']]
.Object@GML_SCHEMA_LOCATION = 'http://schemas.opengis.net/gml/3.1.1/base/feature.xsd'

values(.Object) = values
Expand Down
10 changes: 5 additions & 5 deletions R/04-webprocess-obj.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ setClass(
prototype = prototype(
version = gconfig('version'),
WPS_SCHEMA_LOCATION = 'http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd',
WPS_NAMESPACE = 'http://www.opengis.net/wps/1.0.0',
WPS_NAMESPACE = pkg.env$NAMESPACES[['wps']],
XSI_SCHEMA_LOCATION = 'http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd',
XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance',
OGC_NAMESPACE = 'http://www.opengis.net/ogc',
XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink',
OWS_NAMESPACE = 'http://www.opengis.net/ows/1.1',
XSI_NAMESPACE = pkg.env$NAMESPACES[['xsi']],
OGC_NAMESPACE = pkg.env$NAMESPACES[['ogc']],
XLINK_NAMESPACE = pkg.env$NAMESPACES[['xlink']],
OWS_NAMESPACE = pkg.env$NAMESPACES[['ows']],
emailK = 'gov.usgs.cida.gdp.wps.algorithm.communication.EmailWhenFinishedAlgorithm'
),
representation = representation(
Expand Down
2 changes: 1 addition & 1 deletion R/algorithm-webprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ setMethod(f = "algorithm",signature="XMLAbstractDocument",
definition = function(.Object){
xpath <- "//wps:Execute/ows:Identifier"

algo <- getNodeSet(.Object, xpath)
algo <- getNodeSet(.Object, xpath, namespaces = pkg.env$NAMESPACES)
if (length(algo) != 1) {
stop("Invalid XML, algorithm must be defined (or only once)")
}
Expand Down
3 changes: 2 additions & 1 deletion R/algorithmVersion-webprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ algorithmVersion <- function(knife){
'service' = 'WPS', 'version' = version(knife),'request' = 'DescribeProcess', 'identifier'=algorithm(knife)[[1]]))
doc <- gcontent(getCaps)

version <- xmlAttrs(getNodeSet(doc,'//ProcessDescription')[[1]])[['processVersion']]
version <- xmlAttrs(getNodeSet(doc,'//ProcessDescription',
namespaces = pkg.env$NAMESPACES)[[1]])[['processVersion']]
return(version)
}
8 changes: 5 additions & 3 deletions R/geoknife-generic.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ parseXMLalgorithms <- function(xml){
childKey <- "ows:Identifier"
titleKey <- "ows:Title"

nodes <- getNodeSet(xml, sprintf("//%s/%s",parentKey,childKey))
nodes <- getNodeSet(xml, sprintf("//%s/%s",parentKey,childKey),
namespaces = pkg.env$NAMESPACES)
values <- lapply(nodes,xmlValue)

nodes <- getNodeSet(xml, sprintf("//%s/%s",parentKey,titleKey))
nodes <- getNodeSet(xml, sprintf("//%s/%s",parentKey,titleKey),
namespaces = pkg.env$NAMESPACES)
names(values) <- sapply(nodes,xmlValue)

return(values)
Expand All @@ -116,7 +118,7 @@ parseXMLgeoms <- function(xml){
key="Name"
# ignore namespaces
xpath <- sprintf("//*[local-name()='%s']/*[local-name()='%s']/*[local-name()='%s']",parentKey,childKey,key)
nodes <- getNodeSet(xml, xpath)
nodes <- getNodeSet(xml, xpath, namespaces = pkg.env$NAMESPACES)
values <- sapply(nodes,xmlValue)
return(values)
}
Expand Down
2 changes: 1 addition & 1 deletion R/inputs-webprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ setMethod(f = "inputs",signature = "XMLAbstractDocument",
definition = function(.Object, ...){
inputXpath <- "//wps:Execute/wps:DataInputs/wps:Input"

inputs <- getNodeSet(.Object, inputXpath)
inputs <- getNodeSet(.Object, inputXpath, namespaces = pkg.env$NAMESPACES)
results <- list()
names <- c()
for (i in 1:length(inputs)) {
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-webdata_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ test_that("create webdata from geojob", {
expect_is(url(wd), "character")
expect_is(variables(wd), "character")
expect_gt(length(variables(wd)), 0)

#test XML missing time slots
testthat::skip_on_cran()
noTimesJob <- geojob('https://cida.usgs.gov/gdp/process/request?id=b327be82-8bd5-4a7e-8fda-4288c1a6ef3d')
wd <- webdata(noTimesJob)
expect_equal(length(times(wd)), 2)
expect_is(times(wd), "POSIXct")
})

context("Test getting fields of webdata object")
Expand Down

0 comments on commit ea70886

Please sign in to comment.