Name

ST_Envelope — Returns a geometry representing the bounding box of the supplied geometry.

Synopsis

geometry ST_Envelope(geometry g1);

Description

Returns the float4 minimum bounding box for the supplied geometry, as a geometry. The polygon is defined by the corner points of the bounding box ((MINX, MINY), (MINX, MAXY), (MAXX, MAXY), (MAXX, MINY), (MINX, MINY)). (PostGIS will add a ZMIN/ZMAX coordinate as well).

Degenerate cases (vertical lines, points) will return a geometry of lower dimension than POLYGON, ie. POINT or LINESTRING.

[Caution]

In PostGIS, the bounding box of a geometry is represented internally using float4s instead of float8s that are used to store geometries. The bounding box coordinates are floored, guarenteeing that the geometry is contained entirely within its bounds. This has the advantage that a geometry's bounding box is half the size as the minimum bounding rectangle, which means significantly faster indexes and general performance. But it also means that the bounding box is NOT the same as the minimum bounding rectangle that bounds the geometry.

This method implements the OpenGIS Simple Features Implementation Specification for SQL.

This method implements the SQL/MM specification: SQL-MM 3: 5.1.15

Examples

SELECT ST_AsText(ST_Envelope('POINT(1 3)'::geometry));
 st_astext
------------
 POINT(1 3)
(1 row)


SELECT ST_AsText(ST_Envelope('LINESTRING(0 0, 1 3)'::geometry));
		   st_astext
--------------------------------
 POLYGON((0 0,0 3,1 3,1 0,0 0))
(1 row)


SELECT ST_AsText(ST_Envelope('POLYGON((0 0, 0 1, 1.0000001 1, 1.0000001 0, 0 0))'::geometry));
						  st_astext
--------------------------------------------------------------
 POLYGON((0 0,0 1,1.00000011920929 1,1.00000011920929 0,0 0))
(1 row)
SELECT ST_AsText(ST_Envelope('POLYGON((0 0, 0 1, 1.0000000001 1, 1.0000000001 0, 0 0))'::geometry));
						  st_astext
--------------------------------------------------------------
 POLYGON((0 0,0 1,1.00000011920929 1,1.00000011920929 0,0 0))
(1 row)
	
SELECT ST_Box3D(geom), ST_Box2D(geom), ST_AsText(ST_Envelope(geom)) As envelopewkt
	FROM (SELECT 'POLYGON((0 0, 0 1000012333334.34545678, 1.0000001 1, 1.0000001 0, 0 0))'::geometry As geom) As foo;

box3d
-----------------------------------------
BOX3D(0 0 0,1.0000001 1000012333334.35 0)

box2d
------------------------------------------
BOX(0 0,1.00000011920929 1000012382208)

envelopewkt
-------------------------------------------------------------------
POLYGON((0 0,0 1000012382208,1.00000011920929 1000012382208,1.00000011920929 0,0 0))
	

See Also

ST_Box2D, ST_Box3D