Home

poly2nb

poly2nb is a function in the spdep package for R that constructs a neighbor list (an object of class nb) representing contiguity-based adjacency among polygonal features. It takes a SpatialPolygons or SpatialPolygonsDataFrame object (from the sp package) and returns, for each polygon, the indices of neighboring polygons.

Adjacency is defined by contiguity between polygons. By default, poly2nb uses rook contiguity, where two polygons

The function accepts optional arguments to control labeling and handling of geometries, and it relies on topological

Typical uses include creating neighborhood structures for regional analysis, spatial autocorrelation studies, and various spatial regression

are
considered
neighbors
if
they
share
a
boundary
of
non-zero
length.
A
common
option
is
to
use
queen
contiguity
(setting
queen
=
TRUE),
which
also
treats
polygons
that
touch
at
a
single
point
(vertex)
as
neighbors.
The
resulting
nb
object
can
be
converted
to
a
spatial
weights
matrix
for
use
in
spatial
econometric
models
and
analyses,
for
example
with
nb2listw
or
nb2mat.
tests
to
determine
adjacency.
It
is
applicable
to
polygons
with
holes
or
to
disjoint
sets
of
polygons,
though
polygons
that
do
not
touch
any
others
will
have
empty
neighbor
lists.
Users
should
ensure
the
input
polygons
are
valid
topologically
to
avoid
errors.
models
(such
as
SAR
or
CAR
models).
poly2nb
is
a
foundational
step
for
translating
polygon
geometries
into
neighbor
relationships
that
drive
many
spatial
analyses,
and
it
serves
as
a
bridge
between
polygon
data
and
weighted
spatial
representations.