I wonder how can I define if the polygon has an open edge or not. I consider that polygon does not have an open edge if it is completely surrounded by neighbors.
Using wonderful poly2nb(fc)
I get back the list of neighbors: but, from this list, I don't know how many neighbors the cell has to have to be completely surrounded by neighbors? Here is the situation:
My central red
polygon has in both cases 3 neighbors, but has open edge (left) or is completely surrounded by neighbors (right). If using raster
format and queen case, completely surrounded cell requires 8 neighbors. If it is less, it is open cell. But, can I get something similar from poly2nb(fc)
and nb
object? Of course, my data can contain slivers and gaps between individual polygons, so I don't want entirely rely on overlapping edges or something else.
My real data is available on dropbox or googleDrive
And r code example to calculate the amount of neighbors:
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)
How can I differentiate between completely surrounded polygons and polygons with open edge?