首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多边形有开边吗?考虑R {spdep}中的完全/部分邻居

多边形有开边吗?考虑R {spdep}中的完全/部分邻居
EN

Stack Overflow用户
提问于 2020-01-27 09:53:25
回答 1查看 121关注 0票数 2

我想知道如何定义,如果多边形有一个开边或没有。我认为,如果多边形完全被邻居包围,它就没有开边。

使用奇妙的poly2nb(fc),我可以得到邻居的列表:但是,从这个列表中,我不知道有多少邻居必须被邻居完全包围?情况如下:

在这两种情况下,我的中心red多边形都有3个邻居,但是有开边(左),或者被邻居完全包围(右)。如果使用raster格式和皇后case,则完全包围单元需要8个邻居。如果它少了,它就是开放的细胞。但是,我可以从poly2nb(fc)nb对象获得类似的信息吗?当然,我的数据可以包含单个多边形之间的条条和空白,所以我不想完全依赖于重叠的边缘或其他东西。

我的真实数据可以在dropboxgoogleDrive上获得

以及计算邻居数量的r代码示例:

代码语言:javascript
复制
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)

如何区分完全包围的多边形和开边的多边形?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-09 14:53:59

该方案结合了邻域和基于距离的邻域。邻居是离中央看台在缓冲范围内的看台。在下列情况下,展台具有开阔的边缘:

  • 没有邻居
  • 近邻林分与周围林分的树高差小于5。
  • 如果空间擦除‘缓冲器-邻居’大于一定值,这里我使用16米。

下面是一个考虑到开放边缘的不同情况的模式,但是它有相同数量的邻居:

我的函数逐行遍历shapefile。对于每一行,它基于缓冲区标识一组邻居,并将其与其邻居的高度进行比较。如果差值小于5,则通过从缓冲区中擦除邻居来另外检查间隙是否存在。

以下是整个功能:

代码语言:javascript
复制
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米时,我的开阔地站是:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59928665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档