R/MultiPolygon.r

# OpenSilex API
#
# No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
#
# OpenAPI spec version: 1.0.0-rc+2
# 
# Generated by: https://github.com/swagger-api/swagger-codegen.git


#' MultiPolygon Class
#'
#' @field type 
#' @field bbox 
#' @field coordinates 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
MultiPolygon <- R6::R6Class(
  'MultiPolygon',
  public = list(
    `type` = NULL,
    `bbox` = NULL,
    `coordinates` = NULL,
    initialize = function(`type`, `bbox`, `coordinates`){
      if (!missing(`type`)) {
        stopifnot(is.character(`type`), length(`type`) == 1)
        self$`type` <- `type`
      }
      if (!missing(`bbox`)) {
        stopifnot(is.list(`bbox`), length(`bbox`) != 0)
        lapply(`bbox`, function(x) stopifnot(is.character(x)))
        self$`bbox` <- `bbox`
      }
      if (!missing(`coordinates`)) {
        stopifnot(is.list(`coordinates`), length(`coordinates`) != 0)
        lapply(`coordinates`, function(x) stopifnot(R6::is.R6(x)))
        self$`coordinates` <- `coordinates`
      }
    },
    toJSON = function() {
      MultiPolygonObject <- list()
      if (!is.null(self$`type`)) {
        MultiPolygonObject[['type']] <- self$`type`
      }
      if (!is.null(self$`bbox`)) {
        MultiPolygonObject[['bbox']] <- self$`bbox`
      }
      if (!is.null(self$`coordinates`)) {
        MultiPolygonObject[['coordinates']] <- lapply(self$`coordinates`, function(x) x$toJSON())
      }

      MultiPolygonObject
    },
    fromJSON = function(MultiPolygonJson) {
      MultiPolygonObject <- jsonlite::fromJSON(MultiPolygonJson)
      if (!is.null(MultiPolygonObject$`type`)) {
        self$`type` <- MultiPolygonObject$`type`
      }
      if (!is.null(MultiPolygonObject$`bbox`)) {
        self$`bbox` <- MultiPolygonObject$`bbox`
      }
      if (!is.null(MultiPolygonObject$`coordinates`)) {
        self$`coordinates` <- lapply(MultiPolygonObject$`coordinates`, function(x) {
          coordinatesObject <- LngLatAlt$new()
          coordinatesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE, null = "null"))
          coordinatesObject
        })
      }
    },
    fromJSONObject = function(MultiPolygonObject) {
      if (!is.null(MultiPolygonObject$`type`)) {
        self$`type` <- MultiPolygonObject$`type`
      }
      if (!is.null(MultiPolygonObject$`bbox`)) {
        self$`bbox` <- MultiPolygonObject$`bbox`
      }
      if (!is.null(MultiPolygonObject$`coordinates`)) {
        self$`coordinates` <- lapply(MultiPolygonObject$`coordinates`, function(x) {
          coordinatesObject <- LngLatAlt$new()
          coordinatesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE, null = "null"))
          coordinatesObject
        })
      }
    },
    toJSONString = function() {
      coordinatesList = paste(lapply(self$`coordinates`, function(x) x$toJSONString()),collapse = ",")
       sprintf(
        '{
           "type": %s,
           "bbox": [%s],
           "coordinates": [%s]
        }',
        ifelse(is.null(self$`type`), "null",jsonlite::toJSON(self$`type`,auto_unbox=TRUE, null = "null")),
        ifelse(is.null(self$`bbox`) || length(self$`bbox`) == 0, "" ,lapply(self$`bbox`, function(x) paste(paste0('"', x, '"'), sep=","))),
        coordinatesList
      )
    },
    fromJSONString = function(MultiPolygonJson) {
      MultiPolygonObject <- jsonlite::fromJSON(MultiPolygonJson)
      self$`type` <- MultiPolygonObject$`type`
      self$`bbox` <- MultiPolygonObject$`bbox`
      self$`coordinates` <- lapply(MultiPolygonObject$`coordinates`, function(x) LngLatAlt$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
OpenSILEX/opensilexClientToolsR documentation built on Jan. 28, 2022, 5:03 a.m.