# libpysal.weights.nonplanar_neighbors

libpysal.weights.nonplanar_neighbors(w, geodataframe, tolerance=0.001, **kwargs)

  Detect neighbors for non-planar polygon collections

  Parameters:
    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.

    **kwargs: keyword arguments

      optional arguments for `pysal.weights.W`

  Attributes:
    non_planar_joins `dictionary`

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

  Returns:
    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.

  Notes

  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.

  References

  Planar Enforcement: http://ibis.geog.ubc.ca/courses/klink/gis.notes/ncgia/u12.html#SEC12.6

  Examples

      >>> import geopandas as gpd
      >>> import libpysal
      >>> df = gpd.read_file(libpysal.examples.get_path('map_RS_BR.shp'))
      >>> w = libpysal.weights.Queen.from_dataframe(df)
      >>> 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 = libpysal.weights.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