Skip to content

Instantly share code, notes, and snippets.

@RCura
Created October 3, 2018 09:40
Show Gist options
  • Save RCura/dbe100047a57d6c6ee4adc3fc0733773 to your computer and use it in GitHub Desktop.
Save RCura/dbe100047a57d6c6ee4adc3fc0733773 to your computer and use it in GitHub Desktop.
sector-ize a circle
library(sf)
# Create the base circle polygon
circle <- st_geometry(st_point(c(1E6,1E6))) %>%
st_sfc(crs = 2154) %>%
st_buffer(dist = 1000)
# Create regularly spaced points around polygon
perim_points <- circle %>%
st_cast("LINESTRING") %>%
st_line_sample(n = (360/5)) # The angle of each polygon
# Create voronoi around those points and cut it inside the circle
sectors <- perim_points %>%
st_voronoi(envelope = circle) %>%
st_collection_extract("POLYGON") %>%
st_intersection(circle)
plot(sectors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment