shapely.minimum_rotated_rectangle

shapely.minimum_rotated_rectangle#

minimum_rotated_rectangle(geometry, **kwargs)#

Compute the oriented envelope (minimum rotated rectangle) of the input geometry.

The oriented envelope encloses an input geometry, such that the resulting rectangle has minimum area.

Unlike envelope this rectangle is not constrained to be parallel to the coordinate axes. If the convex hull of the object is a degenerate (line or point) this degenerate is returned.

The starting point of the rectangle is not fixed. You can use normalize() to reorganize the rectangle to strict canonical form so the starting point is always the lower left point.

minimum_rotated_rectangle is an alias for oriented_envelope.

Parameters:
geometryGeometry or array_like

Geometry or geometries for which to compute the oriented envelope.

**kwargs

See NumPy ufunc docs for other keyword arguments.

Examples

>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.oriented_envelope(MultiPoint([(0, 0), (10, 0), (10, 10)])).normalize()
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)])).normalize()
<POLYGON ((1 1, 10 10, 12 8, 3 -1, 1 1))>
>>> shapely.oriented_envelope(Polygon([(1, 1), (15, 1), (5, 10), (1, 1)])).normalize()
<POLYGON ((1 1, 5 10, 16.691 4.804, 12.691 -4.196, 1 1))>
>>> shapely.oriented_envelope(LineString([(1, 1), (10, 1)])).normalize()
<LINESTRING (1 1, 10 1)>
>>> shapely.oriented_envelope(Point(2, 2))
<POINT (2 2)>
>>> shapely.oriented_envelope(GeometryCollection([]))
<POLYGON EMPTY>