多边形的边缘是否开放?考虑R {spdep}

问题描述 投票:2回答:1
中的全部/部分邻居

我想知道如何定义如果多边形是否具有开放边缘。我认为,如果多边形完全被邻居包围,则多边形没有开放的边缘。

使用出色的poly2nb(fc),我得到了邻居列表:但是,从这个列表中,我不知道该小区必须被邻居完全包围多少个邻居?情况如下:

enter image description here

我的中央red多边形在两种情况下都具有3个邻居,但是具有开放的边缘(左)或被邻居完全包围(右)。如果使用raster格式和queen case,则完全包围的单元需要8个邻居。如果小于,则为开孔。但是,我可以从poly2nb(fc)nb对象获得类似的东西吗?当然,我的数据可以包含各个多边形之间的碎片和间隙,因此我不希望完全依赖重叠的边或其他东西。

我的真实数据在dropboxgoogleDrive 上可用

和r代码示例来计算邻居数量:

setwd("U:/Desktop/raw/myDir")

# Read input forest stand data
forest_fc = readOGR(getwd(), 
                    layer = "forest_fc")

# continuity based neighbourhood: 
# import whole 
# shapefile, do not split it by one feature at time
nb <- poly2nb(forest_fc, 
              #row.names = forest_fc,
              snap = 0) # snap to correct for the gaps/slivers 

# store the number of neighbours by cell
forest_fc$nb_count<- card(nb)

plot(forest_fc, 
     col = "white",
     border = "grey")
plot(nb, 
     coordinates(forest_fc), 
     add = T, 
     lwd = 2, 
     col = "black",
     pch = 16,
     cex = 0.5)
text(forest_fc, "nb_count", col = "red", cex = 1.2)

define open edge

如何区分完全包围的多边形和具有开放边缘的多边形?

r spatial nearest-neighbor neighbours
1个回答
0
投票

此解决方案结合了基于连续性和距离的邻域。相邻的机架是在距中央机架缓冲距离之内的机架。如果出现以下情况,则支架具有开放边缘:

  • 没有邻居
  • 邻居和周围林分的树高之间的差异小于5
  • 如果空间擦除的“缓冲区-邻居”大于某个值,那么我使用16 m。

这里是一个考虑开放边缘的不同情况的模式,但是具有相同数量的邻居:

enter image description here

我的函数逐行循环通过shapefile。对于每一行,它基于缓冲区标识一组邻居,然后将高位机架与其邻居进行比较。如果差异小于5,则通过从缓冲区中擦除邻居来另外检查间隙的存在。

这里是整个功能:

defineOpenEdge <- function(spdf, treeHeight, distance = 10, pixel.width = 16, ...) {

  # loop through the dataframe
  spdf@data$open_edge <- FALSE
  for (i in seq_along(spdf)) {

    # define stands and leftover forest
    one  = spdf[i, ]
    left = spdf[-i,]

    # Create buffer and intersectb buffer with neighbors: evalues if any are left?
    buff = buffer(one, distance)


    # Identify neighbors 
    nbrs.buff <- left[which(gOverlaps(sp::geometry(buff),
                                      sp::geometry(left), 
                                      byid = TRUE)),]

    # Conditions for open edge:
    #    - no neighbors
    if (nrow(nbrs.buff) == 0) {
      spdf@data[i,]$open_edge <- TRUE  

    } else {  # neighbors are smaller than the stands

      # Compare the height of the stands: 
      height.one  = rep(one@data$treeHeight, nrow(nbrs.buff))
      height.nbrs = nbrs.buff@data$treeHeight

      # Get the differences between the neighbouring stands
      difference = height.one - height.nbrs

      # compare here the tree heights of stands
      if(any(difference > 5)) {
        spdf@data[i,]$open_edge <- TRUE

      # Check if there is a big gap in neighborhood    
      } else {                     

        # Get the difference between two shapefiles???
        int.buff.one = rgeos::gDifference(buff, nbrs.buff + one)

        # Is the size of the openning larger than one pixel 16x16 m? 
        if (!is.null(int.buff.one) ) {

          # Calculate area of intersected data
          int.buff.one.area = gArea(int.buff.one)

          if (int.buff.one.area > 16*16) {
            spdf@data[i,]$open_edge <- TRUE
          }
        }
      }
    }
  }
 return(spdf) 
} 

这将确定看台是否具有开放边缘。在缓冲区大小为10 m时,我的开放式看台是:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.