geometries are not
graphs are
a data structure that consists of a set of objects called nodes and a set of connections between them called edges
\[ \begin{array}{cccc} 0 & w_{12} & \dots & w_{1N} \\ w_{21} & \ddots & w_{ij} & \vdots \\ \vdots & w_{ji} & 0 & \vdots \\ w_{N1} & \dots & \dots & 0 \end{array} \]
\[ \begin{array}{cccc} 0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array} \]
mathematical structure capturing spatial relationships
it depends
Starting with some polygons…
Focus on this one. Which are its neighbours?
Based on (rook) contiguity, these.
Here is a complete graph.
Here is a complete graph.
Everything within a distance is a neighbour.
Just like this.
Here is a complete graph. A bit denser.
Here is a complete graph. A bit denser.
Only a set number of nearest geometries are neighbours.
In this case \(k=5\).
And a graph.
And a graph.
This would be the same with \(k=1\).
This would be the same with \(k=1\).
Let’s assume five regions.
Let’s assume four regions. Each polygon belongs to one.
All geometries within a region are neighbours.
Graph forms isolated components.
Graph forms isolated components.
Let’s bring back contiguity.
Order 2 of contiguity
Order 3 of contiguity
Order 4 of contiguity
Let’s bring back KNN with \(k=1\).
You can identify connected components.
Look at 20 nearest neighbours.
The closer a neighbour is, the higher the weight it has.
time to code
from libpysal import graph