pysal.lib.weights.nonplanar_neighbors(w, geodataframe, tolerance=0.001)[source]

Detect neighbors for non-planar polygon collections

w: pysal W

A spatial weights object with reported islands

geodataframe: GeoDataframe

The polygon dataframe from which w was constructed.

tolerance: float

The percentage of the minimum horizontal or vertical extent (minextent) of the dataframe to use in defining a buffering distance to allow for fuzzy contiguity detection. The buffering distance is equal to tolerance*minextent.

w: pysal W

Spatial weights object that encodes fuzzy neighbors. This will have an attribute non_planar_joins to indicate what new joins were detected.


This relaxes the notion of contiguity neighbors for the case of shapefiles that violate the condition of planar enforcement. It handles three types of conditions present in such files that would result in islands when using the regular PySAL contiguity methods. The first are edges for nearby polygons that should be shared, but are digitized separately for the individual polygons and the resulting edges do not coincide, but instead the edges intersect. The second case is similar to the first, only the resultant edges do not intersect but are “close”. The final case arises when one polygon is “inside” a second polygon but is not encoded to represent a hole in the containing polygon.

The buffering check assumes the geometry coordinates are projected.


Planar Enforcement:


>>> import geopandas as gpd
>>> import pysal.lib
>>> df = gpd.read_file(pysal.lib.examples.get_path('map_RS_BR.shp'))
>>> w = pysal.lib.weights.contiguity.Queen.from_dataframe(df)
>>> import pysal.lib
>>> w.islands
[0, 4, 23, 27, 80, 94, 101, 107, 109, 119, 122, 139, 169, 175, 223, 239, 247, 253, 254, 255, 256, 261, 276, 291, 294, 303, 321, 357, 374]
>>> wnp = pysal.lib.weights.util.nonplanar_neighbors(w, df)
>>> wnp.islands
>>> w.neighbors[0]
>>> wnp.neighbors[0]
[23, 59, 152, 239]
>>> wnp.neighbors[23]
[0, 45, 59, 107, 152, 185, 246]

Also see nonplanarweights.ipynb

non_planar_joins : dictionary

Stores the new joins detected. Key is the id of the focal unit, value is a list of neighbor ids.