Skip to main content
Returns the minimum-width rotated rectangle enclosing a geometry. Unlike ST_OrientedEnvelope, which minimizes the area of the enclosing rectangle, this function minimizes the width (shortest side). The result may differ from ST_OrientedEnvelope for geometries where the minimum-area and minimum-width orientations diverge (see example below). Degenerate inputs may result in a Point or LineString being returned. ST_MinimumWidthRectangle

Signatures

ST_MinimumWidthRectangle(geom: Geometry)

Parameters

geom
Geometry
required
The input geometry.

Return type

The resulting geometry.

Examples

For a right triangle, ST_MinimumWidthRectangle tilts the rectangle along the hypotenuse to minimize the width, while ST_OrientedEnvelope keeps it axis-aligned to minimize area:
SELECT ST_MinimumWidthRectangle(ST_GeomFromWKT('POLYGON ((0 0, 5 0, 0 3, 0 0))'))
POLYGON ((5 0, 3.68 -2.21, -1.32 0.79, 0 3, 5 0))
Compare with ST_OrientedEnvelope on the same input:
SELECT ST_OrientedEnvelope(ST_GeomFromWKT('POLYGON ((0 0, 5 0, 0 3, 0 0))'))
POLYGON ((0 3, 5 3, 5 0, 0 0, 0 3))