I’m trying to write Python code to detect if there are gaps between polygons.
To do this I simplify some polygon geometries to create gaps, then I thought I could recombine and count the number of boundaries, assuming the anything greater than 1 would indicate a gap:
import geopandas as gpd
gdf = gpd.read_file("ne_50m_admin_0_countries_lakes.shp")
gdf = gdf[gdf["SUBREGION"] == "Northern Africa"]
simplified = gdf.geometry.simplify(0.7)
combined_polygons = gpd.GeoDataFrame(geometry=simplified).dissolve().explode()
bounds = combined_polygons.boundary
In theory it works for examples like this:
But there are other cases where things don’t work as expected (increasing the ‘simplify’ value produces only one multilinestring present):
Can anyone recommend a better way of doing this?