R/GeometryCollection.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


#' GeometryCollection Class
#'
#' @field type 
#' @field bbox 
#' @field coordinates 
#' @field geometries 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
GeometryCollection <- R6::R6Class(
  'GeometryCollection',
  public = list(
    `type` = NULL,
    `bbox` = NULL,
    `coordinates` = NULL,
    `geometries` = NULL,
    initialize = function(`type`, `bbox`, `coordinates`, `geometries`){
      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(is.character(x)))
        self$`coordinates` <- `coordinates`
      }
      if (!missing(`geometries`)) {
        stopifnot(is.list(`geometries`), length(`geometries`) != 0)
        lapply(`geometries`, function(x) stopifnot(R6::is.R6(x)))
        self$`geometries` <- `geometries`
      }
    },
    toJSON = function() {
      GeometryCollectionObject <- list()
      if (!is.null(self$`type`)) {
        GeometryCollectionObject[['type']] <- self$`type`
      }
      if (!is.null(self$`bbox`)) {
        GeometryCollectionObject[['bbox']] <- self$`bbox`
      }
      if (!is.null(self$`coordinates`)) {
        GeometryCollectionObject[['coordinates']] <- self$`coordinates`
      }
      if (!is.null(self$`geometries`)) {
        GeometryCollectionObject[['geometries']] <- lapply(self$`geometries`, function(x) x$toJSON())
      }

      GeometryCollectionObject
    },
    fromJSON = function(GeometryCollectionJson) {
      GeometryCollectionObject <- jsonlite::fromJSON(GeometryCollectionJson)
      if (!is.null(GeometryCollectionObject$`type`)) {
        self$`type` <- GeometryCollectionObject$`type`
      }
      if (!is.null(GeometryCollectionObject$`bbox`)) {
        self$`bbox` <- GeometryCollectionObject$`bbox`
      }
      if (!is.null(GeometryCollectionObject$`coordinates`)) {
        self$`coordinates` <- GeometryCollectionObject$`coordinates`
      }
      if (!is.null(GeometryCollectionObject$`geometries`)) {
        self$`geometries` <- lapply(GeometryCollectionObject$`geometries`, function(x) {
          geometriesObject <- GeoJsonObject$new()
          geometriesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE, null = "null"))
          geometriesObject
        })
      }
    },
    fromJSONObject = function(GeometryCollectionObject) {
      if (!is.null(GeometryCollectionObject$`type`)) {
        self$`type` <- GeometryCollectionObject$`type`
      }
      if (!is.null(GeometryCollectionObject$`bbox`)) {
        self$`bbox` <- GeometryCollectionObject$`bbox`
      }
      if (!is.null(GeometryCollectionObject$`coordinates`)) {
        self$`coordinates` <- GeometryCollectionObject$`coordinates`
      }
      if (!is.null(GeometryCollectionObject$`geometries`)) {
        self$`geometries` <- lapply(GeometryCollectionObject$`geometries`, function(x) {
          geometriesObject <- GeoJsonObject$new()
          geometriesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE, null = "null"))
          geometriesObject
        })
      }
    },
    toJSONString = function() {
      geometriesList = paste(lapply(self$`geometries`, function(x) x$toJSONString()),collapse = ",")
       sprintf(
        '{
           "type": %s,
           "bbox": [%s],
           "coordinates": [%s],
           "geometries": [%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=","))),
        ifelse(is.null(self$`coordinates`) || length(self$`coordinates`) == 0, "" ,lapply(self$`coordinates`, function(x) paste(paste0('"', x, '"'), sep=","))),
        geometriesList
      )
    },
    fromJSONString = function(GeometryCollectionJson) {
      GeometryCollectionObject <- jsonlite::fromJSON(GeometryCollectionJson)
      self$`type` <- GeometryCollectionObject$`type`
      self$`bbox` <- GeometryCollectionObject$`bbox`
      self$`coordinates` <- GeometryCollectionObject$`coordinates`
      self$`geometries` <- lapply(GeometryCollectionObject$`geometries`, function(x) GeoJsonObject$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
OpenSILEX/opensilexClientToolsR documentation built on Jan. 28, 2022, 5:03 a.m.