geojson_atomize: Atomize

Description Usage Arguments Details Value Examples

View source: R/geojson_atomize.R

Description

Atomize

Usage

1
geojson_atomize(x, combine = TRUE)

Arguments

x

(geo_list/geo_json/json/character) input object, either geo_json, geo_list, json, or character class. If character, must be valid JSON

combine

(logical) only applies to geo_json/json type inputs. combine valid JSON objects into a single valid JSON object. Default: TRUE

Details

A FeatureCollection is split into many Feature's, and a GeometryCollection is split into many geometries

Internally we use jqr for JSON parsing

Value

same class as input object, but modified

Examples

 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
################# lists 
# featurecollection -> features
mylist <- list(list(latitude=30, longitude=120, marker="red"),
          list(latitude=30, longitude=130, marker="blue"))
(x <- geojson_list(mylist))
geojson_atomize(x)

# geometrycollection -> geometries
mylist <- list(list(latitude=30, longitude=120, marker="red"),
          list(latitude=30, longitude=130, marker="blue"))
(x <- geojson_list(mylist, type = "GeometryCollection"))
geojson_atomize(x)

# sf class
library(sf)
p1 <- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0))
poly <- rbind(c(1,1), c(1,2), c(2,2), c(1,1))
poly_sfg <- st_polygon(list(p1))
(x <- geojson_list(poly_sfg))
geojson_atomize(x)

################# json 
# featurecollection -> features
mylist <- list(list(latitude=30, longitude=120, marker="red"),
               list(latitude=30, longitude=130, marker="blue"))
(x <- geojson_json(mylist))
geojson_atomize(x)
geojson_atomize(x, FALSE)

# geometrycollection -> geometries
mylist <- list(list(latitude=30, longitude=120, marker="red"),
               list(latitude=30, longitude=130, marker="blue"))
(x <- geojson_json(mylist, type = "GeometryCollection"))
geojson_atomize(x)
geojson_atomize(x, FALSE)

# sf class
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
(x <- geojson_json(nc))
geojson_atomize(x)
geojson_atomize(x, FALSE)

################# character
# featurecollection -> features
mylist <- list(list(latitude=30, longitude=120, marker="red"),
               list(latitude=30, longitude=130, marker="blue"))
(x <- geojson_json(mylist))
geojson_atomize(unclass(x))

geojsonio documentation built on Jan. 15, 2021, 3:33 p.m.