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.
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.
# 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)
box.exterior
(though it does work at runtime). I found that switching to box.boundary
produced the same results and type checks with mypy (and also does not show warnings in PyCharm).
Commented
Aug 8 at 12:34
The typical length of a Polygon is the perimeter of the outer ring. If you require something else, I see in Shapely 1.6 there is a new method, minimum_rotated_rectangle. This produces the smallest rotated rectangle that encloses the Polygon. By calculating the distance between consecutive points, you should be able to determine the width (smallest distance) and length (largest distance) of your MBR. Shapely 1.6 pdf