I need to union polygons of the shapefile using python.
https://i.stack.imgur.com/qY6gD.png
There are some self-intersection inside polygon and my python code always results in error.
import geopandas as gpd
from shapely.geometry import Polygon
from shapely.validation import make_valid
from shapely.ops import cascaded_union
from shapely.validation import explain_validity
pz32 = gpd.read_file("B://_Shp_robocze//test//test.shp")
shp = gpd.geoseries.GeoSeries([geom for geom in pz32.unary_union.geoms])
shp.geometry = shp.apply(lambda row: make_valid(row.geometry) if not row.geometry.is_valid else row.geometry, axis=1)
print(shp)
Errors that console printing
TopologyException: side location conflict at 389425.99965310335 578312.21068473824. This can occur if the input geometry is invalid.
Traceback (most recent call last):
File "C:\...\PycharmProjects\pythonProject\main.py", line 8, in <module>
shp = gpd.geoseries.GeoSeries([geom for geom in pz32.unary_union.geoms])
File "C:\...\PycharmProjects\pythonProject\venv\lib\site-packages\geopandas\base.py", line 800, in unary_union
return self.geometry.values.unary_union()
File "C:\...\PycharmProjects\pythonProject\venv\lib\site-packages\geopandas\array.py", line 650, in unary_union
return vectorized.unary_union(self.data)
File "C:\...\PycharmProjects\pythonProject\venv\lib\site-packages\geopandas\_vectorized.py", line 1034, in unary_union
return shapely.ops.unary_union(data)
File "C:\...\PycharmProjects\pythonProject\venv\lib\site-packages\shapely\ops.py", line 161, in unary_union
return geom_factory(lgeos.methods['unary_union'](collection))
File "C:\...\PycharmProjects\pythonProject\venv\lib\site-packages\shapely\geometry\base.py", line 73, in geom_factory
raise ValueError("No Shapely geometry can be created from null value")
ValueError: No Shapely geometry can be created from null value
How to make this geometry valid ?