【发布时间】:2020-07-21 23:28:11
【问题描述】:
我有一个包含 1000 多个重叠多边形的大型 shapefile。我正在尝试在这些不与图层中的任何多边形重叠的多个重叠多边形之外的组合区域。这些实际上是火灾多次燃烧的区域,我正在寻找火灾只燃烧一次的区域。
我不知道如何找到没有任何重叠的外部区域。你能帮忙吗?
这是一个可重现的例子。
#make some overlapping polygons
m = rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))
p = st_polygon(list(m))
n = 100
l = vector("list", n)
for (i in 1:n)
l[[i]] = p + 2 * runif(2)
s = st_sfc(l)
#select just a few of these
s5 <- s[1:5]
#now try to step through and get the non-overlapping areas
counter <- 0
sall.out <- list()
for (i in 1:length(s5)) {
print(i)
s5.sel <- s5[i]
s5.out <- s5[!(s5 == s5.sel)] #select all the polygons outside
s5.int <- st_intersection(s5.out, s5.sel) #intersect the outside polygons with the one selected
#step through and find all differences between the selected region and the intersected
for (j in 1:length(s5.int)) {
print(j)
s5.out <- st_difference(s5.sel, s5.int[j])
counter <- counter+1
sall.out[[counter]] <- s5.out
}
}
plot(s5)
plot(s5.sel, add=T, col="red")
plot(s5.int, add=T, col="blue")
plot(s5.out, add=T, col="pink")
所以,现在我将所有的 sall.out 都放在了一个列表中,但是如何删除彼此重叠的那些并展平列表呢?
谢谢。
【问题讨论】:
标签: r polygon subtraction sf