如何用 sf 和 R 将一个圆分成相等的 MULTIPOLYGON "slices"?

How do I partition a circle into equal MULTIPOLYGON "slices" with sf and R?

我有这个圈子:

library(sf)
p <- st_sfc(st_point(c(0, 1))) 
circle <- st_buffer(p, dist = 1)  
plot(circle)

如何将这个圆分成 4 个相等的 "slices"? 6 等份? 8个相等的切片?等等。我需要返回的对象是 MULTIPOLYGON。

采用这两个函数,一个是在给定圆心、半径、起始角、宽度和圆弧部分的截面数的情况下创建单个楔形,另一个是创建多个具有不同起始角的楔形:

st_wedge <- function(x,y,r,start,width,n=20){
    theta = seq(start, start+width, length=n)
    xarc = x + r*sin(theta)
    yarc = y + r*cos(theta)
    xc = c(x, xarc, x)
    yc = c(y, yarc, y)
    st_polygon(list(cbind(xc,yc)))   
}

st_wedges <- function(x, y, r, nsegs){
    width = (2*pi)/nsegs
    starts = (1:nsegs)*width
    polys = lapply(starts, function(s){st_wedge(x,y,r,s,width)})
    mpoly = st_cast(do.call(st_sfc, polys), "MULTIPOLYGON")
    mpoly
}

然后做这样的事情来获得五个以半径 10 的 5,1 为中心的楔子:

> w5 = st_wedges(5,1,10,5)
> plot(w5)
> class(w5)
[1] "sfc_MULTIPOLYGON" "sfc"             
> axis(1)
> axis(2)