Skip to content

Instantly share code, notes, and snippets.

@datagistips
Created August 10, 2012 15:38
Show Gist options
  • Save datagistips/3315103 to your computer and use it in GitHub Desktop.
Save datagistips/3315103 to your computer and use it in GitHub Desktop.
Neighbord relationships below a certain distance threshold
library(rgdal)
library(spdep)
pol <- readOGR(".", "buildings") # read the data using rgdal
nb <- poly2nb(pol, snap=50) # create a graph. Two buildings are connected if they are 50 meters apart from one another.
pol$nNeigh <- card(nb) # card(nb) gives the neighbor counts
pol$neighGroup <- n.comp.nb(nb)$comp.id # n.comp.nb contains the informations about the disconnected compontents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment