title: Minimal Envelope of set of geometries - Geopandas
body: <p>To be able to do operations on a set of geometries in a geopandas dataframe, I need to be able to determine whether objects are on the outer &quot;rim&quot; of the set. The set of geometries is as follows:</p>
  <p><a href="https://i.stack.imgur.com/ptfdH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ptfdH.png" alt="enter image description here" /></a></p>
  <p>To do this, I would like to create a polygon that perfectly matches the outer bound of the set of geometrical objects. I first thought about using the convex hull of the set:</p>
  <pre><code>convex_hull = Sectioned_geostore_obstacles_geometry.unary_union.convex_hull
  convex_hull = geopandas.GeoDataFrame({'geometry': convex_hull, 'convex_hull':[1]})
  
  ax = Sectioned_geostore_obstacles_geometry['Gondola'].plot(color='red')
  convex_hull.plot(ax=ax, color='green', alpha=0.5)
  </code></pre>
  <p>which results in</p>
  <p><a href="https://i.stack.imgur.com/YCM0z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YCM0z.png" alt="enter image description here" /></a></p>
  <p>but this isn't quite right since what I am looking for isn't convex. The second idea is to use the envelope:</p>
  <pre><code>envelope = Sectioned_geostore_obstacles_geometry.unary_union.envelope
  envelope = geopandas.GeoDataFrame({'geometry': envelope, 'convex_hull':[1]})
  
  ax = Sectioned_geostore_obstacles_geometry['Gondola'].plot(color='red')
  envelope.plot(ax=ax, color='green', alpha=0.5)
  </code></pre>
  <p>which is</p>
  <p><a href="https://i.stack.imgur.com/5e97T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5e97T.png" alt="enter image description here" /></a></p>
  <p>Again, this isn't it. Yet another attempt is to use the cascade_union functionality from shapely:</p>
  <pre><code>from shapely.ops import cascaded_union
  polygons = list(Sectioned_geostore_obstacles_geometry.Gondola)
  boundary = gpd.GeoSeries(cascaded_union(polygons))
  
  </code></pre>
  <p>which is:</p>
  <p><a href="https://i.stack.imgur.com/GBZgG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GBZgG.png" alt="enter image description here" /></a></p>
  <p>But, this isn't it either as it returns a multipolygon instead of the minimal eveloping polygon.
  Basically, I need the envelope to shrink to follow the contour of the set of objects.</p>
  <p>Any insights would be greatly appreciated.</p>
  <p>To test this, I add the following example data:</p>
  <pre><code>test_df =  geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)]),
                                Polygon([(2,2), (4,2), (4,4), (2,4)])])
  test_df = geopandas.GeoDataFrame({'geometry': test_df, 'df1':[1,2]})
  
  convex_hull = test_df.unary_union.convex_hull
  convex_hull = geopandas.GeoDataFrame({'geometry': convex_hull, 'convex_hull':[1]})
  
  ax1 = test_df['geometry'].plot(color='red')
  convex_hull.plot(ax=ax1, color='green', alpha=0.5)
  
  envelope = test_df.unary_union.envelope
  envelope = geopandas.GeoDataFrame({'geometry': envelope, 'convex_hull':[1]})
  
  ax2 = test_df['geometry'].plot(color='red')
  envelope.plot(ax=ax2, color='green', alpha=0.5)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ZPGRV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZPGRV.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/erGa3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/erGa3.png" alt="enter image description here" /></a></p>