I'm trying to construct neighbours list from polygon list for Lower Layer Super Output Areas (LSOA) in London. I got my shapefiles from the London Datastore, by downloading here: https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london
When I read in the 2004 shapefile (LSOA_2004_London_Low_Resolution.shp
) it works perfectly:
ldn <- st_read("statistical-gis-boundaries-london/ESRI/LSOA_2004_London_Low_Resolution.shp")
#make into sp
ldn_sp <- as(ldn, "Spatial")
#create a list of neighbours using the Queen criteria (default, if you want rook chage to queen = FALSE)
w <- poly2nb(ldn_sp)
plot(ldn_sp, border = "grey60")
plot(w, coordinates(ldn_sp), pch = 19, cex = 0.6, add = TRUE)
When I read in the 2011 shapefile (LSOA_2011_London_gen_MHW.shp
) however it seems to think that most of the LSOAs don't have neighbours.
When I use the 2011 one with the same code, I get this:
ldn <- st_read("statistical-gis-boundaries-london/ESRI/LSOA_2011_London_gen_MHW.shp")
ldn_sp <- as(ldn, "Spatial")
w <- poly2nb(ldn_sp)
plot(ldn_sp, border = "grey60")
plot(w, coordinates(ldn_sp), pch = 19, cex = 0.6, add = TRUE)
Does anyone have any ideas what I'm doing wrong? LSOAs which clearly should have neighbours show up with 0 links. I have no idea why...!
Looks like an issue with how the shapefile has been put together - polygons in LSOA_2011_London_gen_MHW.shp
not sharing boundaries completely.
Using the snap argument in poly2nb
will force the function to treat boundaries within a certain defined distance to be contiguous, e.g:
w <- poly2nb(ldn_sp, snap=10)
In above example, 10 = decimal degrees as your original data are in WGS84 - might want to convert to BNG and set a reasonable small distance in metres to snap. You'll need to experiment at bit, but 10 decimal degrees in the quick and dirty example above seems to generate something approximating an expected neighbours list.