ST_MBR function

The ST_MBR function takes a geometry as an input parameter and returns its minimum bounding rectangle.

If the specified geometry is a point, then the point itself is returned. If the geometry is a horizontal linestring or a vertical linestring, the horizontal or vertical linestring itself is returned. If the specified geometry is null or is empty, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramST_MBR(geometry)

Parameter

geometry
A value of type ST_Geometry or one of its subtypes that represents the geometry for which the minimum bounding rectangle is returned.

Return type

ST_Geometry

Example

This example illustrates how the ST_MBR function can be used to return the minimum bounding rectangle of a polygon. Because the specified geometry is a polygon, the minimum bounding rectangle is returned as a polygon.


CREATE TABLE sample_polys (id INTEGER, geometry ST_Polygon)

INSERT INTO sample_polys
  VALUES (1, ST_Polygon ('polygon (( 5 5, 7 7, 5 9, 7 9, 9 11, 13 9,
                                     15 9, 13 7, 15 5, 9 6, 5 5))', 0) )

INSERT INTO sample_polys
  VALUES (2, ST_Polygon ('polygon (( 20 30, 25 35, 30 30, 20 30))', 0) )

SELECT id, CAST (ST_AsText ( ST_MBR(geometry)) AS VARCHAR(150) ) MBR
  FROM sample_polys
Results:

ID        MBR
--------- ----------------------------------------------------------
        1 POLYGON ((5 5, 15 5, 15 11, 5 11, 5 5))                               
        2 POLYGON ((20 30, 30 30, 30 35, 20 35, 20 30))