Python Shapely – How to Get Polygon Breadth

pythonshapely

Is it possible to get polygon breadth in Shapely, similar to how it provides polygon length?
http://toblerity.org/shapely/shapely.geometry.html

I am also ok with a solution that uses fiona or any non-arcgis open source python solution.

Best Answer

# create example polygon
poly = Polygon([(0, 0), (4, 0), (5, 2), (7, 5), (3, 2), (1, 3)])

# get minimum bounding box around polygon
box = poly.minimum_rotated_rectangle

# get coordinates of polygon vertices
x, y = box.exterior.coords.xy

# get length of bounding box edges
edge_length = (Point(x[0], y[0]).distance(Point(x[1], y[1])), Point(x[1], y[1]).distance(Point(x[2], y[2])))

# get length of polygon as the longest edge of the bounding box
length = max(edge_length)

# get width of polygon as the shortest edge of the bounding box
width = min(edge_length)

Polygon with Minimum Bounding Box, Polygon width & Polygon height