*Initial code with rgdal's readOGR function: *
geo <- readOGR("./Data/Carto/COMMUNE_CARTO.shp")
geo2 <- subset(geo, geo@data$INSEE_COM %in% selected_com)
DATA2BND <- sp2bnd(geo2, geo2@data$INSEE_COM)
plot(DATA2BND)
list_names <- as.data.frame(names(DATA2BND)) %>%
group_by(names(DATA2BND)) %>%
summarise(n = n())
nb <- mgcv:::pol2nb(DATA2BND)$nb
W.nb <- poly2nb(
geo2,
row.names = rownames(geo2@data$INSEE_COM)
)
w <- nb2mat(W.nb, style = "B")
*New code with sf and sp: *
geo_sf <- st_read("./Data/Carto/COMMUNE_CARTO.shp", quiet = TRUE)
geo <- as(geo_sf, "Spatial")
geo2 <- subset(geo, geo@data$INSEE_COM %in% selected_com)
DATA2BND <- sp2bnd(geo2, geo2@data$INSEE_COM)
plot(DATA2BND)
list_names <- as.data.frame(names(DATA2BND)) %>%
group_by(names(DATA2BND)) %>%
summarise(n = n())
nb <- mgcv:::pol2nb(DATA2BND)$nb
W.nb <- poly2nb(geo2, row.names = rownames(geo2@data$INSEE_COM), queen=T)
Warning messages:
1: In poly2nb(geo2, row.names = rownames(geo2@data$INSEE_COM), queen = T):
some observations have no neighbors;
if this seems unexpected, try increasing the snap argument.
2: In poly2nb(geo2, row.names = rownames(geo2@data$INSEE_COM), queen = T):
neighbor object has 7 sub-graphs;
if this sub-graph count seems unexpected, try increasing the snap argument.
w_SMD_2025 <- nb2mat(W.nb, style = "B")
Error in nb2listw(neighbors, glist = glist, style = style, zero.policy =
zero.policy):
Empty neighbor sets found (zero.policy: FALSE)
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo