Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. library(sf)
  2.  
  3. # function to get polygon from boundary box
  4. bbox_polygon <- function(x) {
  5. bb <- sf::st_bbox(x)
  6.  
  7. p <- matrix(
  8. c(bb["xmin"], bb["ymin"],
  9. bb["xmin"], bb["ymax"],
  10. bb["xmax"], bb["ymax"],
  11. bb["xmax"], bb["ymin"],
  12. bb["xmin"], bb["ymin"]),
  13. ncol = 2, byrow = T
  14. )
  15.  
  16. sf::st_polygon(list(p))
  17. }
  18.  
  19. nc <- st_centroid(st_read(system.file("shape/nc.shp", package="sf")))["BIR79"]
  20. box <- st_sfc(bbox_polygon(nc))
  21. v <- st_voronoi(nc, box)
  22.  
  23. plot(v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement