我是一个有用的助手,可以为您进行文本翻译。
我正在尝试通过固定距离来缩小一个sf多边形。
以这个简单的多边形为例:
coords <- list(rbind(c(0,0), c(2,0), c(2,2), c(1,2), c(1,1), c(0,1), c(0,0)))
p <- sf::st_polygon(x = coords)
ggplot() + geom_sf(data = p, fill = "white", color = "black")
我想制作一个与原多边形形状相同的多边形,但是所有边缘都与原多边形相比确切地偏移0.1个单位。这是目标:
target.coords <- list(rbind(c(0.1,0.1), c(1.9,0.1), c(1.9,1.9), c(1.1,1.9), c(1.1,0.9), c(0.1,0.9), c(0.1,0.1)))
target <- sf::st_polygon(x = target.coords)
ggplot() +
geom_sf(data = p, fill = "white", color = "black") +
geom_sf(data = target, fill = "green", color = "dark green")
我以为sf::st_buffer()
可以帮我实现,但外角并不完全匹配。p1 <- sf::st_buffer(x = p, dist = -0.1)
ggplot() +
geom_sf(data = p, fill = "white", color = "black") +
geom_sf(data = p1, fill = "red", color = "dark red")
是否有替代设置sf::st_buffer()
的方法,可以让我实现目标多边形?或者是否有其他函数可以实现这一点?偏移量需要是固定距离,而不是相对缩小多边形(例如90%)。