Skip to content

Instantly share code, notes, and snippets.

@kissmygritts
Last active December 3, 2020 01:26
Show Gist options
  • Save kissmygritts/0fa0bf56900a078a80933b1cb2be72d7 to your computer and use it in GitHub Desktop.
Save kissmygritts/0fa0bf56900a078a80933b1cb2be72d7 to your computer and use it in GitHub Desktop.
st_bbox_to_poly <- function (bbox) {
x1 <- bbox[1]
y1 <- bbox[2]
x2 <- bbox[3]
y2 <- bbox[4]
sf::st_polygon(list(matrix(c(
x1, y1,
x1, y2,
x2, y2,
x2, y1,
x1, y1
), ncol = 2, byrow = TRUE)))
}
## give it your bounding box
st_bbox_to_poly(shape) %>%
sf::st_sfc(crs = 4326) %>%
mapview::mapview()
poly <- st_bbox_to_poly(shape) %>%
sf::st_sfc(crs = 4326) %>% st_as_sf()
geojsonsf::sf_geojson(poly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment