英文:
st_buffer with geometry sfc_POINT
问题
我正在处理地理空间数据,对于分析的一部分,我需要使用从Excel获取的地区坐标点,并使用st_as_sf
将这些数据转换为sf对象。当我尝试在这些点周围设置缓冲区时,我可以使用st_buffer(data_as_sf, 2000)
来设置2公里的缓冲区。这在我有几何对象为sfc_MULTIPOLYGON
的形状文件中运行良好。但现在我的几何对象是sfc_POINT
。在这种情况下,我需要如何设置缓冲区?使用常规的st_buffer
方法会起作用吗,还是我需要将其转换为sfc_MULTIPOLYGON
?
英文:
I'm working with geospatial data and for one part of the analysis I need to use coordinate points of regions that I get from an excel and turn that data into sf object using st_as_sf
. When I tried to set a buffer around the points I use st_buffer(data_as_sf, 2000)
for a 2km buffer. This was working well with shapefiles where I had the geometry object as sfc_MULTIPOLYGON
. But now my geometry object is sfc_POINT
. How do I need to set the buffer in this case? Would it work well using regular st_buffer
method or do I need to convert it into sfc_MULTIPOLYGON
?
答案1
得分: 1
为什么不简单地测试一下?
library(sf)
my_point <- st_sfc(st_point(c(0, 0)))
my_buffer <- st_buffer(my_point, 2000)
class(my_point)
#> [1] "sfc_POINT" "sfc"
class(my_buffer)
#> [1] "sfc_POLYGON" "sfc"
plot(my_buffer, axes = TRUE)
plot(my_point, add = TRUE)
我们可以看到st_buffer
正确地创建了一个2,000米的sfc_POLYGON
围绕我们的sfc_POINT
。
创建于2023年02月23日,使用reprex v2.0.2
英文:
Why not simply test it out?
library(sf)
my_point <- st_sfc(st_point(c(0, 0)))
my_buffer <- st_buffer(my_point, 2000)
class(my_point)
#> [1] "sfc_POINT" "sfc"
class(my_buffer)
#> [1] "sfc_POLYGON" "sfc"
plot(my_buffer, axes = TRUE)
plot(my_point, add = TRUE)
We can see that st_buffer
has correctly created a 2,000m sfc_POLYGON
around our sfc_POINT
<sup>Created on 2023-02-23 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论