Last active
December 3, 2020 01:26
-
-
Save kissmygritts/0fa0bf56900a078a80933b1cb2be72d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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