【问题标题】:extend (buffer) boundary of shape file in R在R中扩展(缓冲)形状文件的边界
【发布时间】:2021-06-02 10:32:20
【问题描述】:

我需要将字段的边界(仅边界)扩展 x 米。我尝试使用 rgeos R 包中的 gBuffer - 转换的输出只给了我字段的边界,字段内的其余多边形会随数据丢失。

如何使用 gBuffer / 任何其他方式仅将空间多边形对象(形状文件)的边界扩展 10m 并保持一切完好(多边形和数据内部)

尝试过的代码 -

field <- raster::shapefile("test.shp")
class(field)
plot(field)
View(field@data)

field  <- sp::spTransform(field,CRS("+init=epsg:32632"))
plot(field)

field10m  <- rgeos::gBuffer(field , width = 10)
plot(field10m)

测试shapefile可以从这里下载https://drive.google.com/file/d/1s4NAinDeBow95hxr6gELHHkhwiR3z6Z9/view?usp=sharing

【问题讨论】:

    标签: r raster sf buffer-geometry rgeo-shapefile


    【解决方案1】:

    我建议您考虑基于{sf} 包的工作流程;它使代码比 sp 和 rgeos 更清晰(它将使用相同的几何引擎,但隐藏了引擎盖下的坚韧部分)。

    代码保留了 shapefile 的所有数据特征(实际上,只有一个 - 名为 Rx 的列)。

    请注意,由于黄色元素 / Rx = 120 / 由多个多边形组成,每个多边形都被缓冲,从而导致要素重叠。这是预期的结果。

    如果这是不受欢迎的行为,您可以考虑使用dplyr::group_by(Rx) 后跟dplyr::summarise() 来消除内部边界线,然后再应用sf::st_buffer() 调用。

    library(sf)
    library(dplyr)
    library(mapview) # needed only for the final overview
    library(leafsync) # dtto.
    
    test_map <- sf::st_read("./Map/test.shp")
    
    # find an appropriate projected metric CRS
    crsuggest::suggest_crs(test_map, type = "projected")
    
    result <- test_map %>% 
      sf::st_transform(5683) %>%  # transform to a metric CRS
      sf::st_buffer(10) # buffer by 10 meters
    
    # a visual check / note how the polygons are overlaid
    leafsync::latticeview(mapview::mapview(test_map),
                          mapview::mapview(result))
    

    【讨论】:

    • 感谢您提出“sf”方式,肯定会相应调整,在此解决方案中,内部线(内部多边形)也延长了 10 m,预期结果只是 扩展 10 m ,其他特征保持与初始状态相同
    • @string 啊,我明白了!抱歉太慢了......在这种情况下,我建议使用statnmap.com/2020-07-31-buffer-area-for-nearest-neighbour 中描述的方法 - 它以法国诺曼底部门的海上边界为例,我相信可能会对您的用例有所帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多