Overlay¶
Overlay function that avoids a GEOSException from geopandas.overlay.
This module includes the function ‘clean_overlay’, which bypasses a GEOSException from the regular geopandas.overlay. The function is a generalized version of the solution from GH 2792.
‘clean_overlay’ also includes the overlay type “update”, which can be specified in the “how” parameter, in addition to the five native geopandas how-s.
- clean_overlay(df1, df2, how='intersection', keep_geom_type=None, geom_type=None, predicate='intersects', grid_size=None, n_jobs=1, lsuffix='_1', rsuffix='_2')[source]¶
Fixes and explodes geometries before doing a shapely overlay, then cleans up.
Fixes geometries, then does a shapely overlay operation that dodges a GEOSException raised in the regular geopandas.overlay. The function is a generalised version of a solution from GH 2792.
- Parameters:
df1 (
GeoDataFrame
) – GeoDataFramedf2 (
GeoDataFrame
) – GeoDataFramehow (
str
) – Method of spatial overlay. Includes the ‘update’ method, plus the five native geopandas methods ‘intersection’, ‘union’, ‘identity’, ‘symmetric_difference’ and ‘difference’.keep_geom_type (
bool
|None
) – If True (default), return only geometries of the same geometry type as df1 has, if False, return all resulting geometries.geom_type (
str
|None
) – optionally specify what geometry type to keep before the overlay, if there are mixed geometry types. Must be either “polygon”, “line” or “point”.grid_size (
float
|None
) – Precision grid size to round the geometries. Will use the highest precision of the inputs by default.n_jobs (
int
) – number of threads.predicate (
str
|None
) – Spatial predicate in the spatial tree.lsuffix (
str
) – Suffix of columns in df1 that are also in df2.rsuffix (
str
) – Suffix of columns in df2 that are also in df1.
- Return type:
GeoDataFrame
- Returns:
GeoDataFrame with overlayed and fixed geometries and columns from both GeoDataFrames.
- Raises:
ValueError – If ‘how’ is not one of ‘intersection’, ‘union’, ‘identity’, ‘symmetric_difference’, ‘difference’ or ‘update’.
- make_valid_and_keep_geom_type(geoms, geom_type, n_jobs)[source]¶
Make GeometryCollections into (Multi)Polygons, (Multi)LineStrings or (Multi)Points.
Because GeometryCollections might appear after dissolving (unary_union). And this makes shapely difference/intersection fail.
- Parameters:
geoms (
ndarray
) – Array of geometries.geom_type (
str
) – geometry type to be kept.n_jobs (
int
) – Number of treads.
- Return type:
GeoSeries