
Last chance! 50% off unlimited learning
Sale ends in
Add or get bounding box
bbox_add(x, bbox = NULL)bbox_get(x)
bbox_add: an object of class jqson/character from jqr
bbox_get: a bounding box, of the form
[west, south, east, north]
for 2D or of the form
[west, south, min-altitude, east, north, max-altitude]
for 3D
An object of class geojson
(numeric) a vector or list of length 4 for a 2D bounding box
or length 6 for a 3D bounding box. If NULL
, the bounding box is
calculated for you
Note that bbox_get
outputs the bbox if it exists, but
does not calculate it from the geojson. See geo_bbox
to calculate a bounding box. Bounding boxes can be 2D or 3D.
# make a polygon
x <- '{ "type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
}'
(y <- polygon(x))
# add bbox - without an input, we figure out the 2D bbox for you
y %>% feature() %>% bbox_add()
## 2D bbox
y %>% feature() %>% bbox_add(c(100.0, -10.0, 105.0, 10.0))
## 3D bbox
y %>% feature() %>% bbox_add(c(100.0, -10.0, 3, 105.0, 10.0, 17))
# get bounding box
z <- y %>% feature() %>% bbox_add()
bbox_get(z)
## returns NULL if no bounding box
bbox_get(x)
Run the code above in your browser using DataLab