bbox gets bounding boxes

Various interfaces:

  • Input long/lat and value to make a polyogn, then get the bbox, using either
    • sp/rgeos, or
    • GeoJSON via lawn (to be replaced with geoops once geoops::geo_buffer)
  • Input Spatial objects (sp package) and spit out the bbox
  • Input GeoJSON data and spit out the bbox
  • Input Well Know Text data and spit out the bbox
  • Input Simple Features (sf package) data and spit out the bbox

Installation

remotes::install_github("ropensci/bbox")
library("bbox")

lon/lat to bbox

lonlat2bbox(lon=-120, lat=45, width=10^4)
#> [1] -120.08983   44.93644 -119.91017   45.06349

get bbox from any spatial object

sp/rgeos class spatial objects

library(sp)
x <- GridTopology(c(0,0), c(1,1), c(5,5))
sp_grid <- SpatialGrid(x)
b_box(sp_grid)
#> [1] -0.5 -0.5  4.5  4.5

WKT

wkt_poly <- "POLYGON ((100.001 0.001, 101.1235 0.0010, 101.001 1.001, 100.001 0.001))"
b_box(wkt_poly)
#> [1] 100.0010   0.0010 101.1235   1.0010

visualize bbox’es

library(leaflet)
viz_bbox <- function(map, x) addRectangles(map, x[1], x[2], x[3], x[4])
leaflet() %>%
    addTiles() %>%
    viz_bbox(lonlat2bbox(lon=-120, lat=45, width=10)) %>%
    viz_bbox(lonlat2bbox(-120, 45, 100)) %>%
    viz_bbox(lonlat2bbox(-120, 45, 1000)) %>%
    viz_bbox(lonlat2bbox(-120, 45, 10^4)) %>%
    viz_bbox(lonlat2bbox(-120, 45, 10^5)) %>%
    viz_bbox(lonlat2bbox(-120, 45, 10^6))

map

Meta