如何获得多个多边形的交点?

问题描述 投票:0回答:1

我有一个'SpatialPolygonsDataFrame'列表,我想接收所有这些多边形的交集。我已经在stackoverflow.com上找到了一些如何解决此问题的提示,不过,我想知道我的错误消息的答案。

请参阅网址:https://gis.stackexchange.com/questions/140504/extracting-intersection-areas-in-r网址:https://gis.stackexchange.com/questions/156660/loop-to-check-multiple-polygons-overlap-in-r

length_b_loop <- length(as.vector(dat_ftprints))-1
# dat_ftprints is the list of 25 SpatialPolygonsDataFrame

for (b in length_b_loop){
  if (b == 1){
    spc_intersect_poly1 <- dat_ftprints[[b]]
    spc_intersect_poly2 <- dat_ftprints[[b+1]]
    spc_intersect_temp <- raster::intersect(spc_intersect_poly1, spc_intersect_poly2)
  } else {
    spc_intersect_poly3 <- dat_ftprints[[b+1]]
    spc_intersect_temp <- raster::intersect(spc_intersect_temp, spc_intersect_poly3)
  }
}
# get a single polygon which represents the intersection of all polygons stored in the list

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'

非常感谢!干杯,ExplorerR

r gis spatial raster sp
1个回答
0
投票

我无法确认这一点,因为您没有提供可重复的示例,但是for循环中似乎有错误。您仅在值24而不是值1到24上进行迭代。这意味着未正确创建spc_intersect_temp,并且仍是您为其分配的最后一个值。试试这个:

length_b_loop <- length(dat_ftprints)-1

for (b in 1:length_b_loop){
  if (b == 1){
    spc_intersect_poly1 <- dat_ftprints[[b]]
    spc_intersect_poly2 <- dat_ftprints[[b+1]]
    spc_intersect_temp <- raster::intersect(spc_intersect_poly1, spc_intersect_poly2)
  } else {
    spc_intersect_poly3 <- dat_ftprints[[b+1]]
    spc_intersect_temp <- raster::intersect(spc_intersect_temp, spc_intersect_poly3)
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.