Skip to content

Commit

Permalink
#9 GetCoverage extended/tested to WCS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Feb 23, 2022
1 parent ae1c5bc commit d6c28c4
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export(PropertyIsNull)
export(UnaryLogicOpType)
export(WCSCapabilities)
export(WCSClient)
export(WCSCoverage)
export(WCSCoverageDescription)
export(WCSCoverageDomain)
export(WCSCoverageSpatialDomain)
Expand Down
107 changes: 107 additions & 0 deletions R/WCSCoverage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#' WCSCoverage
#'
#' @docType class
#' @export
#' @keywords OGC WCS Coverage
#' @return Object of \code{\link{R6Class}} modelling a WCS coverage
#' @format \code{\link{R6Class}} object.
#'
#' @note Class used internally by ows4R.
#'
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
WCSCoverage <- R6Class("WCSCoverage",
inherit = OGCAbstractObject,
private = list(
identifier = NA,
title = NA,
abstract = NA,
reference = NA,

#fetchCoverage
fetchCoverage = function(xmlObj, serviceVersion, owsVersion){
children <- xmlChildren(xmlObj)
covIdentifier <- NULL
if(!is.null(children$Identifier)){
covIdentifier <- xmlValue(children$Identifier)
}
covTitle <- NULL
if(!is.null(children$Title)){
covTitle <- xmlValue(children$Title)
}
covAbstract <- NULL
if(!is.null(children$Abstract)){
covAbstract <- xmlValue(children$Abstract)
}
covRef <- NULL
if(!is.null(children$Reference)){
covRef <- xmlGetAttr(children$Reference, "xlink:href")
}

coverage <- list(
identifier = covIdentifier,
title = covTitle,
abstract = covAbstract,
reference = covRef
)

return(coverage)

}

),
public = list(
#'@field description description
description = NULL,

#'@description Initializes an object of class \link{WCSCoverage}
#'@param xmlObj object of class \link{XMLInternalNode-class}
#'@param serviceVersion WCS service version
#'@param owsVersion OWS version
#'@param logger logger
initialize = function(xmlObj, serviceVersion, owsVersion, logger = NULL){
super$initialize(logger = logger)

coverage = private$fetchCoverage(xmlObj, serviceVersion, owsVersion)
private$identifier = coverage$identifier
private$title = coverage$title
private$abstract = coverage$abstract
private$reference = coverage$reference
},

#'@description Get identifier
#'@return an object of class \code{character}
getIdentifier = function(){
return(private$identifier)
},

#'@description Get title
#'@return an object of class \code{character}
getTitle = function(){
return(private$title)
},

#'@description Get abstract
#'@return an object of class \code{character}
getAbstract = function(){
return(private$abstract)
},

#'@description Get reference
#'@return an object of class \code{character}
getReference = function(){
return(private$reference)
},

#'@description Get data
#'@return an object of class \code{RasterLayer}
getData = function(){
tmp <- tempfile()
req <- httr::GET(private$reference)
bin <- content(req, "raw")
writeBin(bin, tmp)
r <- raster::raster(tmp)
return(r)
}
)
)
23 changes: 15 additions & 8 deletions R/WCSCoverageSummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ WCSCoverageSummary <- R6Class("WCSCoverageSummary",
#'@param crs crs. Default is \code{NULL}
#'@param time time. Default is \code{NULL}
#'@param elevation elevation. Default is \code{NULL}
#'@param format format. Default is "image/tiff"
#'@param format format. Default will be GeoTIFF, coded differently depending on the WCS version.
#'@param rangesubset rangesubset. Default is \code{NULL}
#'@param gridbaseCRS grid base CRS. Default is \code{NULL}
#'@param gridtype grid type. Default is \code{NULL}
Expand All @@ -329,7 +329,7 @@ WCSCoverageSummary <- R6Class("WCSCoverageSummary",
#'@return an object of class \link{raster} from \pkg{raster}
getCoverage = function(bbox = NULL, crs = NULL,
time = NULL, elevation = NULL,
format = "image/tiff", rangesubset = NULL,
format = NULL, rangesubset = NULL,
gridbaseCRS = NULL, gridtype = NULL, gridCS = NULL,
gridorigin = NULL, gridoffsets = NULL, ...){
coverage_data <- NULL
Expand All @@ -352,7 +352,14 @@ WCSCoverageSummary <- R6Class("WCSCoverageSummary",
}else if(substr(private$version,1,3)=="2.0"){
#TODO check format in case of WCS2
}

}else{
if(substr(private$version,1,3)=="1.0"){
format <- "GeoTIFF"
}else if(substr(private$version,1,3)=="1.1"){
format <- "image/tiff"
}else if(substr(private$version,1,3)=="2.0"){
format <- "image/tiff"
}
}

#crs
Expand Down Expand Up @@ -391,7 +398,7 @@ WCSCoverageSummary <- R6Class("WCSCoverageSummary",
envelope <- switch(substr(private$version,1,3),
"1.0" = {
owsbbox <- self$getWGS84BoundingBox()[[1]]
OWSUtils$toBBOX(owsbbox$LowerCorner[1], owsbbox$UpperCorner[1], owsbbox$LowerCorner[2], owsbbox$UpperCorner[2])
OWSUtils$toBBOX(owsbbox$LowerCorner[[1]], owsbbox$UpperCorner[[1]], owsbbox$LowerCorner[[2]], owsbbox$UpperCorner[[2]])
},
"1.1" = {
bboxes <- self$getDescription()$getDomain()$getSpatialDomain()$BoundingBox
Expand Down Expand Up @@ -515,7 +522,7 @@ WCSCoverageSummary <- R6Class("WCSCoverageSummary",

#response handling
if(substr(private$version,1,3)=="1.1"){
#for WFS 1.1, wrap with WCSCoverage object and get data
#for WCS 1.1, wrap with WCSCoverage object and get data
namespaces <- OWSUtils$getNamespaces(xmlRoot(resp))
namespaces <- as.data.frame(namespaces)
nsVersion <- ""
Expand All @@ -525,12 +532,12 @@ WCSCoverageSummary <- R6Class("WCSCoverageSummary",
wcsNamespaceURI <- paste("http://www.opengis.net/wcs", nsVersion, sep ="/")
wcsNs <- OWSUtils$findNamespace(namespaces, uri = wcsNamespaceURI)
if(is.null(wcsNs)) wcsNs <- OWSUtils$findNamespace(namespaces, id = "wcs")
print(wcsNs)
xmlObj <- getNodeSet(resp, "//ns:Coverage", wcsNs)[[1]]
coverage <- WCSCoverage$new(xmlObj = xmlObj, private$version, private$owsVersion, logger = self$loggerType)
coverage_data <- coverage$getData()
}else if(substr(private$version,1,3)=="2.0"){
#for WCS 2.0.x take directly the data
#}else if(substr(private$version,1,3)=="2.0"){
}else{
#for WCS 1.0.x / 2.0.x take directly the data
tmp <- tempfile()
writeBin(resp, tmp)
coverage_data <- raster::raster(tmp)
Expand Down
2 changes: 1 addition & 1 deletion R/WCSGetCoverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ WCSGetCoverage <- R6Class("WCSGetCoverage",
if(startsWith(serviceVersion,"1.0")){
if(!is.null(envelope)) namedParams$BBOX <- paste0(as(envelope, "character"), collapse=",")
if(!is.null(crs)) namedParams$CRS <- crs
if(!is.null(time)) namedParams$Timesequence <- paste0(time, collapse=",")
if(!is.null(time)) namedParams$time <- paste0(time, collapse=",")
}
if(startsWith(serviceVersion,"1.1")){
#envelope object as matrix
Expand Down
169 changes: 169 additions & 0 deletions man/WCSCoverage.Rd

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

4 changes: 2 additions & 2 deletions man/WCSCoverageSummary.Rd

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

Loading

0 comments on commit d6c28c4

Please sign in to comment.