【发布时间】:2018-08-27 12:10:12
【问题描述】:
如何在包含多个多边形的 shapefile 中合并多边形特征?
rbind 和 union 只是结合了 shapefile 特征的行,它们实际上并没有合并多边形本身。
以下示例中的所需结果:
如何在 sptemp 中将以下具有重复 ID_2 的 shapefile 合并到单个多边形?
埃塞俄比亚 GADM 级别 2 的以下示例具有重复的 shapefile ID_2 列的前两行(值=1)。我想要具有 79 个功能的 sptemp,前两行是具有重复 ID_2 的行。 sptemp[1,] 的图将显示当前 sptemp[1,] 和 sptemp2[2,] 没有重复之间的边界,即多边形也被合并。
示例代码:
下载、解压缩并加载到埃塞俄比亚 2 级的 R GADM 文件(工作目录为 899kb):
library(curl)
library(rgdal)
curl_download("http://biogeo.ucdavis.edu/data/gadm2.8/shp/ETH_adm_shp.zip",
destfile=paste0("gadmETH.zip"),
quiet=FALSE)
unzip(paste0("gadmETH.zip"), exdir="gadmETH", overwrite=FALSE)
###Load shapefile
sptemp <- readOGR(dsn="gadmETH", layer="ETH_adm2")
前两个多边形的 ID_2 列重复
###You'll see in the first two rows ID_2 is duplicated
df.sptemp <- as.data.frame(sptemp)
View(sptemp)
###I can't just delete one because they are separate polygons
plot(sptemp[1,], col="blue")
plot(sptemp[2,], add=TRUE, col="red" )
【问题讨论】: