在R中以矩阵格式计算多边形对的重叠面积

3

我正在尝试计算多个多边形之间的重叠区域面积和百分比。例如,我有5个多边形,我想计算每对多边形之间的重叠区域面积和百分比。是否有一种方法可以运行一个包含所有多边形(shapefiles)的函数,并获得一个矩阵输出,显示每对多边形的值? 我希望得到这样的输出:

overlap    poly 1     poly 2    poly 3     poly 4 poly 5

poly 1

poly 2

poly 3

poly 4

poly 5

我用来计算一对多边形重叠百分比的公式如下:

AreaOverlap/(SQRT(AreaPolyA*AreaPolyB))

谢谢!


多边形的格式是什么?是x.y坐标还是直接给出面积?需要更多信息。 - Mandar
@Mandar 不同的多边形是我加载到R中的不同shapefile,因此在一个坐标系中。 - Stijn
@Wimpel 如果我使用的数据是我在R中加载的shapefile,那么我可以使用dput()提供样本数据吗? - Stijn
@Wimpel 如果有帮助的话,这里是三个shapefile的链接示例。这些shapefile是动物家庭范围,每个shp包含三个不同的多边形(50%,75%,95%核密度概率)。理想情况下,我只需要不同shapefile相同概率的重叠值。因此,不同shp之间95%多边形的重叠,75%和50%也是如此。但是例如不需要50%和95%之间的重叠。 https://wetransfer.com/downloads/fec5effe5ffe961c006dc51e5275697020190117140921/edf93f2129df9525f994664a405e8b8f20190117140921/528ff6 - Stijn
@Wimpel,你有没有更多的建议,我如何使用shapefiles运行类似的代码? - Stijn
显示剩余2条评论
1个回答

9
没有样本数据,我认为一个可能的解决方案是:
创建一些样本数据。
library( sf)
#square of 2 x 2
pol = st_polygon(list(rbind(c(0,0), c(2,0), c(2,2), c(0,2), c(0,0))))
#add two more squares of 2 x 2
b = st_sfc(pol, pol + c(.8, .2), pol + c(4, .8))

plot(b)

在这里输入图片描述

计算重叠面积


l <- lapply( b, function(x) { 
       lapply(b, function(y) st_intersection( x, y ) %>% st_area() ) 
     })

matrix(unlist(l), ncol = length(b), byrow = TRUE)
#      [,1] [,2] [,3]
# [1,] 4.00 2.16    0
# [2,] 2.16 4.00    0
# [3,] 0.00 0.00    4

计算重叠百分比

l2 <- lapply( b, function(x) { 
  lapply(b, function(y) st_intersection( x, y ) %>% st_area() * 100 /sqrt( st_area(x) * st_area(y) ) ) 
})

matrix(unlist(l2), ncol = length(b), byrow = TRUE)
#      [,1] [,2] [,3]
# [1,]  100   54    0
# [2,]   54  100    0
# [3,]    0    0  100

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接