I have a polygon shapefile in which I want to fill holes in the polygons that are smaller than a certain threshold (area_min_hole_sqm in sample code below). I am new to geoprocessing in python. I have found several threads which explain how to do this using shapely, but I'm hoping to stick to geopandas if possible. If shapely is the only way to do it, then I'm struggling with how to convert the geopandas format (geodataframe) to a shapely polygon and back again - especially because my shapefile has 15 attributes that need to remain in the final result. The examples I find all start with a very simple "Polygon(List of coordinates)," while I have a complex shapefile.
This is what I have so far:
import geopandas as gpd # Read + explode polygon shapefile shp = gpd.read_file(r"c:\Users\xx\Documents\Model\input\floodmap.shp").to_crs(epsg=32752) shp_exp = shp.explode() # Fill holes in polygons area_min_hole_sqm = 100000 shp_filled = ??? # Dissolve and write polygon shapefile shp_filled_diss = shp_filled.dissolve() shp_filled_diss.to_file(r"c:\Users\xx\Documents\Model\output\floodmap_filled.shp", index=False)