This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
/
MultiPoint.r
102 lines (96 loc) · 3.71 KB
/
MultiPoint.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Netherlands Biodiversity Api
#
# Access to the digitised Natural History collection at the Naturalis Biodiversity Center
#
# OpenAPI spec version: v2
# Contact: support@naturalis.nl
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' MultiPoint Class
#'
#' @field crs
#' @field bbox
#' @field coordinates
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
MultiPoint <- R6::R6Class(
"MultiPoint",
public = list(
`crs` = NULL,
`bbox` = NULL,
`coordinates` = NULL,
initialize = function(`crs`, `bbox`, `coordinates`) {
if (!missing(`crs`)) {
stopifnot(R6::is.R6(`crs`))
self[["crs"]] <- `crs`
}
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`
}
},
toList = function() {
MultiPointList <- list()
if (!is.null(self[["crs"]])) {
MultiPointList[["crs"]] <- self[["crs"]]$toList()
}
if (!is.null(self[["bbox"]])) {
MultiPointList[["bbox"]] <- self[["bbox"]]
}
if (!is.null(self[["coordinates"]])) {
MultiPointList[["coordinates"]] <- lapply(self[["coordinates"]], function(x) x$toList())
}
## omit empty nested lists in returned list
MultiPointList[vapply(MultiPointList, length, FUN.VALUE = integer(1)) > 0]
},
fromList = function(MultiPointList, typeMapping = NULL) {
if (is.null(typeMapping[["crs"]])) {
self[["crs"]] <- Crs$new()$fromList(MultiPointList[["crs"]], typeMapping = typeMapping)
} else {
obj <- eval(parse(text = paste0(typeMapping[["crs"]], "$new()")))
self[["crs"]] <- obj$fromList(MultiPointList[["crs"]], typeMapping = typeMapping)
}
if (is.null(typeMapping[["bbox"]])) {
self[["bbox"]] <- MultiPointList[["bbox"]]
} else {
obj <- eval(parse(text = paste0(typeMapping[["bbox"]], "$new()")))
self[["bbox"]] <- obj$fromList(MultiPointList[["bbox"]], typeMapping = typeMapping)
}
self[["coordinates"]] <- lapply(
MultiPointList[["coordinates"]],
function(x) LngLatAlt$new()$fromList(x, typeMapping = typeMapping)
)
invisible(self)
},
toJSONString = function(pretty = T) {
jsonlite::toJSON(self$toList(), simplifyVector = T, auto_unbox = T, pretty = pretty)
},
fromJSONString = function(MultiPointJson, typeMapping = NULL) {
MultiPointList <- jsonlite::fromJSON(MultiPointJson, simplifyVector = F)
if (is.null(typeMapping[["crs"]])) {
self[["crs"]] <- Crs$new()$fromJSONString(jsonlite::toJSON(MultiPointList[["crs"]], auto_unbox = TRUE), typeMapping = typeMapping)
} else {
obj <- eval(parse(text = paste0(typeMapping[["crs"]], "$new()")))
self[["crs"]] <- obj$fromJSONString(jsonlite::toJSON(MultiPointList[["crs"]], auto_unbox = TRUE), typeMapping = typeMapping)
}
if (is.null(typeMapping[["bbox"]])) {
self[["bbox"]] <- MultiPointList[["bbox"]]
} else {
obj <- eval(parse(text = paste0(typeMapping[["bbox"]], "$new()")))
self[["bbox"]] <- obj$fromJSONString(jsonlite::toJSON(MultiPointList[["bbox"]], auto_unbox = TRUE), typeMapping = typeMapping)
}
self[["coordinates"]] <- lapply(
MultiPointList[["coordinates"]],
function(x) LngLatAlt$new()$fromJSONString(jsonlite::toJSON(x, auto_unbox = TRUE), typeMapping = typeMapping)
)
invisible(self)
}
)
)