我想知道如何定义,如果多边形有一个开边或没有。我认为,如果多边形完全被邻居包围,它就没有开边。
使用奇妙的poly2nb(fc),我可以得到邻居的列表:但是,从这个列表中,我不知道有多少邻居必须被邻居完全包围?情况如下:

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

如何区分完全包围的多边形和开边的多边形?
发布于 2020-03-09 14:53:59
该方案结合了邻域和基于距离的邻域。邻居是离中央看台在缓冲范围内的看台。在下列情况下,展台具有开阔的边缘:
下面是一个考虑到开放边缘的不同情况的模式,但是它有相同数量的邻居:

我的函数逐行遍历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米时,我的开阔地站是:

https://stackoverflow.com/questions/59928665
复制相似问题