有没有办法在 R 中有更好的缓冲区边界?
Is there a way to have better buffer borders in R?
我希望有人可以帮助我解决以下情况。
我正在做一个项目,我需要在 R 中围绕质心绘制一个圆(半径)。我还使用这个质心与其他几何图形相交。我面临的问题是缓冲区边界不是一个定义明确的圆,当我绘制圆和交点时看起来不太好。
我的代码看起来有点像这样:
使用 sf 和 ggplot2
方圆100公里
circle = st_buffer(centroid,100000)
对于路口
intersection = st_intersection(geometry,circle)
剧情
ggplot()+geom_sf(data= circle, fill = "yellow")
The border of buffer is "low quality"
还不错!也就是说,如果你真的想平滑 circle/buffer 边界,你可以使用包 smoothr
.
这是一种可能性:
library(smoothr)
# Smooth circle border
circle_smooth <- smooth(densify(circle, max_distance = 10), method = "ksmooth")
# Plot
ggplot2::ggplot()+
ggplot2::geom_sf(data= circle_smooth, fill = "yellow")
您也可以使用sf::st_buffer(..., nQuadSegs=)
来自https://geocompr.robinlovelace.net/geometric-operations.html
The third and final argument of st_buffer() is nQuadSegs, which means ‘number of segments per quadrant’ and is set by default to 30 (meaning circles created by buffers are composed of 4×30=120 lines). This argument rarely needs to be set. Unusual cases where it may be useful include when the memory consumed by the output of a buffer operation is a major concern (in which case it should be reduced) or when very high precision is needed (in which case it should be increased).
我希望有人可以帮助我解决以下情况。 我正在做一个项目,我需要在 R 中围绕质心绘制一个圆(半径)。我还使用这个质心与其他几何图形相交。我面临的问题是缓冲区边界不是一个定义明确的圆,当我绘制圆和交点时看起来不太好。
我的代码看起来有点像这样:
使用 sf 和 ggplot2
方圆100公里
circle = st_buffer(centroid,100000)
对于路口
intersection = st_intersection(geometry,circle)
剧情
ggplot()+geom_sf(data= circle, fill = "yellow")
The border of buffer is "low quality"
还不错!也就是说,如果你真的想平滑 circle/buffer 边界,你可以使用包 smoothr
.
这是一种可能性:
library(smoothr)
# Smooth circle border
circle_smooth <- smooth(densify(circle, max_distance = 10), method = "ksmooth")
# Plot
ggplot2::ggplot()+
ggplot2::geom_sf(data= circle_smooth, fill = "yellow")
您也可以使用sf::st_buffer(..., nQuadSegs=)
来自https://geocompr.robinlovelace.net/geometric-operations.html
The third and final argument of st_buffer() is nQuadSegs, which means ‘number of segments per quadrant’ and is set by default to 30 (meaning circles created by buffers are composed of 4×30=120 lines). This argument rarely needs to be set. Unusual cases where it may be useful include when the memory consumed by the output of a buffer operation is a major concern (in which case it should be reduced) or when very high precision is needed (in which case it should be increased).