0

我需要将字段的边界(仅边界)扩展 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

4

1 回答 1

0

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

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

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

如果这是不受欢迎的行为,您可以考虑在应用调用之前使用 adplyr::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))

上面代码中的两张地图; 旁边

于 2021-06-02T11:28:20.740 回答