PostGISGeometry Accessors

ST_Envelope

What is ST_Envelope?

ST_Envelope is a PostGIS function that returns the minimum axis-aligned bounding box of a geometry as a POLYGON. The output is a five-vertex rectangle in the same SRID as the input; for degenerate cases (point, horizontal/vertical line) the output is a point or linestring.

SQL
ST_Envelope(geometry g)geometry

The computation uses the cached bounding box when possible, making ST_Envelope very cheap on large datasets.

When would you use ST_Envelope?

Use ST_Envelope for quick bounding-box operations — approximate intersections, map extent calculations, or rough visual overlays:

SQL
1SELECT region_id,
2       ST_Envelope(ST_Collect(geom)) AS bbox
3FROM features
4GROUP BY region_id;

It is also a cheap approximate filter — ST_Envelope(a) && ST_Envelope(b) is equivalent to the && bbox operator but returns a geometry you can inspect. For building a bbox from explicit numeric bounds, use ST_MakeEnvelope.

FAQs

What is the difference between ST_Envelope and ST_MakeEnvelope?

ST_Envelope takes a geometry and returns its bounding-box polygon. ST_MakeEnvelope takes four numeric bounds (xmin, ymin, xmax, ymax) and builds a polygon from scratch. Different inputs, similar outputs.

Is ST_Envelope fast?

Very. It uses the cached bounding box associated with every PostGIS geometry, avoiding a vertex scan. Safe to call on millions of rows.

Does ST_Envelope work in 3D?

No — it is strictly 2D and drops Z and M. For 3D bounds use ST_3DMakeBox and the Box3D type.

What does ST_Envelope return for a single point?

A POINT equal to the input coordinate (a zero-area envelope). For a horizontal or vertical line it returns a LINESTRING. Only 2D extents with both nonzero width and height produce a proper polygon.