I am trying to do some spatial generalised linear mixed models for areal unit data with the CARBayes package. As part of this, I need to identify the polygon neighbours into a neighbour list using
The shapefile I have of NSW is located here: Dropbox with shapefile
There is a freely available Australia wide version at: ABS.gov.au but I'm only after NSW.
library(spdep) library(sf) library(sp) library(lwgeom) p <- read_sf("NSW_POA_arc.shp") p.nb <- poly2nb(p) coords <- st_coordinates(st_centroid(st_geometry(p))) # this seems to miss some polygons plot(st_geometry(p), border="grey") plot(p.nb, coords, pch = 19, cex = 0.4, add=TRUE)
For some reason
poly2nb isn't recognising that some of the polygons are neighbours to each other. I've tried using the
snap feature but this only vaguely works at
snap = 0.0001. It also adds connections to non-neighbours.
xx <- poly2nb(p, snap = 0.0001) plot(st_geometry(p), border="grey") plot(xx, coords, pch = 19, cex = 0.4, add=TRUE)
I'm not sure if its a topology issue but
lwgeom::st_is_valid says that the polygons are valid.
Any ideas would be amazing. I'm very new to writting these questions properly so any feedback is welcome. Many thanks