Reference Guide#

Nonplanar Edges#

geoplanar.non_planar_edges(gdf)#

Find coincident nonplanar edges

Parameters
gdfGeoDataFrame with polygon (multipolygon) GeoSeries
Returns
missingdictionary

key is origin feature, value is neighboring feature for each pair of coincident nonplanar edges

Examples

>>> c1 = [[0,0], [0, 10], [10, 10], [10, 0], [0, 0]]
>>> p1 = Polygon(c1)
>>> c2 = [[10, 2], [10, 8], [20, 8], [20, 2], [10, 2]]
>>> p2 = Polygon(c2)
>>> gdf = geopandas.GeoDataFrame(geometry=[p1, p2])
>>> geoplanar.non_planar_edges(gdf)
defaultdict(set, {0: {1}})
geoplanar.is_planar_enforced(gdf)#

Test if a geodataframe has any planar enforcement violations

Parameters
gdf: GeoDataFrame with polygon geoseries for geometry
Returns
boolean
geoplanar.fix_npe_edges(gdf, inplace=False)#

Fix all npe intersecting edges in geoseries.

Returns
gdf: GeoDataFrame with geometries respected planar edges.

Examples

>>> c1 = [[0,0], [0, 10], [10, 10], [10, 0], [0, 0]]
>>> p1 = Polygon(c1)
>>> c2 = [[10, 2], [10, 8], [20, 8], [20, 2], [10, 2]]
>>> p2 = Polygon(c2)
>>> gdf = geopandas.GeoDataFrame(geometry=[p1, p2])
>>> geoplanar.non_planar_edges(gdf)
defaultdict(set, {0: {1}})
>>> gdf1 = geoplanar.fix_npe_edges(gdf)
>>> geoplanar.non_planar_edges(gdf1)
defaultdict(set, {})

Gaps#

geoplanar.gaps(gdf)#

Find gaps in a geodataframe.

A gap (emply sliver polygon) is a set of points that:

  • are not contained by any of the geometries in the geoseries

  • are not contained by the external polygon

Parameters
gdfGeoDataFrame with polygon (multipolygon) GeoSeries
Returns
_gapsGeoDataFrame with gap polygons

Examples

>>> p1 = box(0,0,10,10)
>>> p2 = Polygon([(10,10), (12,8), (10,6), (12,4), (10,2), (20,5)])
>>> gdf = geopandas.GeoDataFrame(geometry=[p1,p2])
>>> h = geoplanar.gaps(gdf)
>>> h.area
array([4., 4.])
geoplanar.fill_gaps(gdf, gap_df=None, largest=True, inplace=False)#

Fill any gaps in a geodataframe.

Parameters
gdfGeoDataFrame with polygon (multipolygon) GeoSeries
gap_df: GeoDataFrame with gaps to fill

If None, gaps will be determined

largest: boolean (Default: True)

Merge each gap with its largest (True), or smallest (False) neighbor. If None, merge with any neighbor non-deterministically but performantly.

inplace: boolean (default: False)

Change the geoseries of current dataframe

Returns
_gapsGeoDataFrame with gap polygons

Examples

>>> p1 = box(0,0,10,10)
>>> p2 = Polygon([(10,10), (12,8), (10,6), (12,4), (10,2), (20,5)])
>>> gdf = geopandas.GeoDataFrame(geometry=[p1,p2])
>>> gdf.area
0    100.0
1     32.0
dtype: float64
>>> h = geoplanar.gaps(gdf)
>>> h.area
array([4., 4.])
>>> gdf1 = geoplanar.fill_gaps(gdf)
>>> gdf1.area
0    108.0
1     32.0
dtype: float64

Holes#

geoplanar.missing_interiors(gdf)#

Find any missing interiors.

For a planar enforced polygon layer, there should be no cases of a polygon being contained in another polygon. Instead the “contained” polygon is a hole in the “containing” polygon.

Parameters
gdfGeoDataFrame with polygon (multipolygon) GeoSeries
Returns
pairslist

tuples for each violation (i,j), where i is the index of the containing polygon, j is the index of the contained polygon

Examples

>>> p1 = box(0,0,10,10)
>>> p2 = box(1,1, 3,3)
>>> p3 = box(7,7, 9,9)
>>> gdf = geopandas.GeoDataFrame(geometry=[p1,p2,p3])
>>> mi = geoplanar.missing_interiors(gdf)
>>> mi
[(0, 1), (0, 2)]
geoplanar.add_interiors(gdf, inplace=False)#

Add any missing interiors.

For a planar enforced polygon layer, there should be no cases of a polygon being contained in another polygon. Instead the “contained” polygon is a hole in the “containing” polygon. This function finds and corrects any such violations.

Parameters
gdfGeoDataFrame with polygon (multipolygon) GeoSeries
inplace: boolean (default: False)

Change the geoseries of current dataframe

Returns
gdfGeoDataFrame

Examples

>>> p1 = box(0,0,10,10)
>>> p2 = box(1,1, 3,3)
>>> p3 = box(7,7, 9,9)
>>> gdf = geopandas.GeoDataFrame(geometry=[p1,p2,p3])
>>> gdf.area
0   100.0
1     4.0
2     4.0
>>> mi = geoplanar.missing_interiors(gdf)
>>> mi
[(0, 1), (0, 2)]
>>> gdf1 = geoplanar.add_interiors(gdf)
>>> gdf1.area
0    92.0
1     4.0
2     4.0