I need to create a neighbours list from a spatial polygon. At the moment i am using the function poly2nb, but unfortunately it is not very accurate, and some polygons with no common points are considered neighbours. I have tried changing the snap argument, but with no luck.
I have however tried the function gTouches from the rgeos package, and it works much better. Only problem is, it creates a list object that cannot be used in spdep. Is there any way to convert it into a nb object?
Thank you in advance! :)
Looking at the source code for the
tri2nbfunction https://rdrr.io/cran/spdep/src/R/tri2nb.R, which I know is a different function than the one you mentioned, you can change thelisttonbtype:class(yourlist) <- "nb"An example:
Initial Result:
Assign the class of mylist as nb
Final Result:
From this, you can continue to use functions in
spdepto select optimal spatial weighting matrices.