0

I'm working with a DataFrame that has a few thousand coordinate points and am plotting them using plotly.express. I want to draw a marker around the perimeter of the points that encompasses all of the points. I've been using geopandas and the convex_hull function, but it doesn't seem to return the smallest possible polygon.

For example, here's what I have so far:

enter image description here

The black line represents a tracer that was added using go.Scattermapbox to connect the points of the smallest possible polygon selected using the convex_hull function. However, as we can see, it doesn't appear to be the smallest possible polygon? There's a lot of space that is open that could be removed to make the polygon smaller.

Here's the code I've been working with in terms of the convex_hull function:

crs = {'init': 'epsg:4326'}
geo_df = gpd.GeoDataFrame(points, crs=crs)
convex_points = geo_df.unary_union.convex_hull
convex_coords = list(convex_points.exterior.coords)
convex_coords = pd.DataFrame(convex_coords, columns=['lon','lat'])

where the points variable is a DataFrame filled with geometry points that were created using the Point function within shapely.

Am I missing something with convex_hull? Is this truly the smallest possible polygon that the function can return? And if so, is there another option to use to get a smaller possible polygon?

Ian Turton
  • 81,417
  • 6
  • 84
  • 185
user216769
  • 23
  • 2
  • 2
    Convex hull gives the smallest convex polygon. You need to look into concave polygons instead. https://gis.stackexchange.com/questions/1200/what-are-definition-algorithms-and-practical-solutions-for-concave-hull – nmpeterson Jan 17 '23 at 15:37
  • 2
    What you are looking for is called Concave hull. or Alpha shape and there are answers in GSE – gene Jan 17 '23 at 15:37

0 Answers0