R/GSDimension.R

#' Geoserver REST API Dimension
#'
#' @docType class
#' @importFrom R6 R6Class
#' @export
#' 
#' @name GSDimension
#' @title A GeoServer dimension
#' @description This class models a GeoServer resource dimension.
#' @keywords geoserver rest api resource dimension
#' @return Object of \code{\link{R6Class}} for modelling a GeoServer dimension
#' @format \code{\link{R6Class}} object.
#' 
#' @examples
#'   dim <- GSDimension$new()
#' 
#' @author Emmanuel Blondel <emmanuel.blondel1@@gmail.com>
#'
GSDimension <- R6Class("GSDimension",
  inherit = GSRESTResource,
  
  public = list(
    #' @field enabled true/false
    enabled = TRUE,
    #' @field presentation dimension presentation
    presentation = NULL,
    #' @field resolution dimension resolution
    resolution = NULL,
    #' @field units dimension units
    units = NULL,
    #' @field unitSymbol dimension unitsSymbol
    unitSymbol = NULL,
    
    #'@description Initializes an object of class \link{GSDimension}
    #'@param xml object of class \link{XMLInternalNode-class}
    initialize = function(xml = NULL){
      super$initialize(rootName = "dimensionInfo")
      if(!missing(xml) & !is.null(xml)){
        self$decode(xml)
      }
    },
   
    #'@description Decodes from XML
    #'@param xml object of class \link{XMLInternalNode-class}
    decode = function(xml){
      propsXML <- xmlChildren(xml)
      props <- lapply(propsXML, xmlValue)
      self$setEnabled(as.logical(props$enabled))
      if(!is.null(props$presentation)) self$setPresentation(props$presentation)
      self$setUnit(props$units)
      self$setUnitSymbol(props$unitSymbol)
    },
    
    #'@description Set enabled
    #'@param enabled enabled
    setEnabled = function(enabled){
      self$enabled = enabled
    },
    
    #'@description Set presentation
    #'@param presentation presentation. Possible values: "LIST", "CONTINUOUS_INTERVAL", "DISCRETE_INTERVAL"
    #'@param interval interval
    setPresentation = function(presentation, interval = NULL){
      supportedPresentations <- c("LIST", "CONTINUOUS_INTERVAL", "DISCRETE_INTERVAL")
      if(!(presentation %in% supportedPresentations)){
        err <- sprintf("Unknown presentation '%s'. Supported values are: [%s]",
                       presentation, paste0(supportedPresentations, collapse=","))
        stop(err)
      }
      self$presentation = presentation
      if(self$presentation == "DISCRETE_INTERVAL"){
        if(missing(interval) | is.null(interval)){
          stop("Interval should be provided for DISCRETE_INTERVAL presentation")
        }
        self$resolution <- interval
      }
    },
    
    #'@description Set unit
    #'@param unit unit
    setUnit = function(unit){
      self$units = unit
    },
    
    #'@description Set unit symbol
    #'@param unitSymbol unit symbol
    setUnitSymbol = function(unitSymbol){
      self$unitSymbol = unitSymbol
    }
   
  )
                         
)

Try the geosapi package in your browser

Any scripts or data that you put into this service are public.

geosapi documentation built on Oct. 4, 2023, 5:06 p.m.