Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(sf)
- # function to get polygon from boundary box
- bbox_polygon <- function(x) {
- bb <- sf::st_bbox(x)
- p <- matrix(
- c(bb["xmin"], bb["ymin"],
- bb["xmin"], bb["ymax"],
- bb["xmax"], bb["ymax"],
- bb["xmax"], bb["ymin"],
- bb["xmin"], bb["ymin"]),
- ncol = 2, byrow = T
- )
- sf::st_polygon(list(p))
- }
- nc <- st_centroid(st_read(system.file("shape/nc.shp", package="sf")))["BIR79"]
- box <- st_sfc(bbox_polygon(nc))
- v <- st_voronoi(nc, box)
- plot(v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement