geopandas.GeoSeries.make_valid#

GeoSeries.make_valid()[source]#

Repairs invalid geometries.

Returns a GeoSeries with valid geometries. If the input geometry is already valid, then it will be preserved. In many cases, in order to create a valid geometry, the input geometry must be split into multiple parts or multiple geometries. If the geometry must be split into multiple parts of the same type to be made valid, then a multi-part geometry will be returned (e.g. a MultiPolygon). If the geometry must be split into multiple parts of different types to be made valid, then a GeometryCollection will be returned.

Examples

>>> from shapely.geometry import MultiPolygon, Polygon, LineString, Point
>>> s = geopandas.GeoSeries(
...     [
...         Polygon([(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 1), (0, 0)]),
...         Polygon([(0, 2), (0, 1), (2, 0), (0, 0), (0, 2)]),
...         LineString([(0, 0), (1, 1), (1, 0)]),
...     ],
... )
>>> s
0    POLYGON ((0 0, 0 2, 1 1, 2 2, 2 0, 1 1, 0 0))
1              POLYGON ((0 2, 0 1, 2 0, 0 0, 0 2))
2                       LINESTRING (0 0, 1 1, 1 0)
dtype: geometry
>>> s.make_valid()
0    MULTIPOLYGON (((1 1, 0 0, 0 2, 1 1)), ((2 0, 1...
1    GEOMETRYCOLLECTION (POLYGON ((2 0, 0 0, 0 1, 2...
2                           LINESTRING (0 0, 1 1, 1 0)
dtype: geometry