我不太擅长R语言和空间分析。我正在寻找一种方法,根据数据框中的字段,将空间多边形数据框内的多边形组合起来:类似于dplyr的“group_by”功能,但是用于spdf。我不确定合并、连接或组合这些词是否正确,但我希望我的需求很清楚。
library(sp)
#coordinates:
xy1 = cbind(c(1,2,2,1),c(1,1,2,2))
xy2 = cbind(c(2,3,3,2),c(1,1,2,2))
xy3 = cbind(c(1,2,2,1),c(2,2,3,3))
xy4 = cbind(c(2,3,3,2),c(2,2,3,3))
#polygons:
p1 = Polygon(xy1)
ps1 = Polygons(list(p1),ID = "a")
p2 = Polygon(xy2)
ps2 = Polygons(list(p2),ID = "b")
p3 = Polygon(xy3)
ps3 = Polygons(list(p3),ID = "c")
p4 = Polygon(xy4)
ps4 = Polygons(list(p4),ID = "d")
#spatial polygons:
sps_m = SpatialPolygons(list(ps1,ps2,ps3,ps4))
#dataframe:
data_m = data.frame(dt = c("Group A","Group B","Group A","Group C"),row.names = c("a","b","c","d"))
#spatial polygons dataframe:
spdf_m = SpatialPolygonsDataFrame(sps_m,data_m)
#plot spdf:
plot(spdf_m)
gUnaryUnion()
。冒昧地说,我最近写了一篇关于多边形溶解的文章:https://philmikejones.me/post/2015-09-03-dissolve-polygons-in-r/ - Philsf
的方式。我非常赞同你的观点! - Fitzroy Hogsflesh