bbox

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Build Status codecov

bbox gets bounding boxes

Various interfaces:

Installation

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

lon/lat to bbox

lonlat2bbox(lon=-120, lat=45, width=10^4)

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)

WKT

wkt_poly <- "POLYGON ((100.001 0.001, 101.1235 0.0010, 101.001 1.001, 100.001 0.001))"
b_box(wkt_poly)

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



ropensci/bbox documentation built on May 15, 2022, 9:06 a.m.