pysal.lib.weights.
fuzzy_contiguity
(gdf, tolerance=0.005, buffering=False, drop=True)[source]¶Fuzzy contiguity spatial weights
Parameters: 


Returns: 

Notes
This relaxes the notion of contiguity neighbors for the case of feature collections that violate the condition of planar enforcement. It handles three types of conditions present in such collections 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.
Detection of the second case will require setting buffering=True and exploring different values for tolerance.
The buffering check assumes the geometry coordinates are projected.
References
Planar Enforcement: http://ibis.geog.ubc.ca/courses/klink/gis.notes/ncgia/u12.html#SEC12.6
Examples
>>> import pysal.lib as lps
>>> import geopandas as gpd
>>> rs = lps.examples.get_path('map_RS_BR.shp')
>>> rs_df = gpd.read_file(rs)
>>> wq = lps.weights.contiguity.Queen.from_dataframe(rs_df)
>>> len(wq.islands)
29
>>> wq[0]
{}
>>> wf = fuzzy_contiguity(rs_df)
>>> wf.islands
[]
>>> wf[0] == dict({239: 1.0, 59: 1.0, 152: 1.0, 23: 1.0, 107: 1.0})
True
Example needing to use buffering
>>> import pysal.lib as lps
>>> import geopandas as gpd
>>> from shapely.geometry import Polygon
>>> p0 = Polygon([(0,0), (10,0), (10,10)])
>>> p1 = Polygon([(10,1), (10,2), (15,2)])
>>> p2 = Polygon([(12,2.001), (14, 2.001), (13,10)])
>>> gs = gpd.GeoSeries([p0,p1,p2])
>>> gdf = gpd.GeoDataFrame(geometry=gs)
>>> wf = fuzzy_contiguity(gdf)
>>> wf.islands
[2]
>>> wfb = fuzzy_contiguity(gdf, buffering=True)
>>> wfb.islands
[]
>>> wfb[2]
{1: 1.0}