# Python Shapely - filling small gaps between multi polygons

I have a set of rectangular polygons, which currently form a directional path. The library I am using is Python Shapely / GeoPandas.

The issue I am having is as the path changes direction, there are small gaps and overlaps between the polygons. I could iterate through all my polygon objects and calculate the angle in between each intersecting point and generate a new set of polygons but I figure there is a much better way.

I am fairly close - using the shapely buffer function, as seen in the following code snippet. I am able to remove the gaps, but it ends up merging my polygons into 1x. But I require them to remain 2x seperate polygons.

``````polygons = MultiPolygon([Polygon([(0, 0.5), (0, 2.5), (1, 2.5),(1,0.5)]),Polygon([(0, 0), (1, 1), (2,0),(1,-1)])])
polygons = polygons.buffer(2).buffer(-2)
`````` • Does shapely have a convex hull method? Which would essentially do what you want. To split them you'll need to create a line at the desired location and difference the line from the poly. – songololo Jul 8 '16 at 8:56

``````from shapely.geometry import MultiPolygon, Polygon
• Thanks! This also pointed me in the right direction. Just a minor note: it is also possible to use convex_hull function from shapely (e.g. import `shapely.geometry as geometry` and then using `polygon = multi_polygon.convex_hull` on a `geometry.multipolygon.MultiPolygon` – Alex Jan 12 '18 at 7:31