PostGISGeometry Constructors

ST_MakeEnvelope

What is ST_MakeEnvelope?

ST_MakeEnvelope is a PostGIS function that builds an axis-aligned rectangular POLYGON from the minimum and maximum X/Y coordinates. It is the standard way to construct a bounding-box geometry for spatial filtering, tile requests, or map-view queries.

SQL
ST_MakeEnvelope(float xmin, float ymin, float xmax, float ymax, integer srid=unknown)geometry

The result is a closed five-vertex polygon (corner ordering: bottom-left, bottom-right, top-right, top-left, bottom-left). If no SRID is supplied, the output has SRID 0; always pass the SRID to match the target column, or the spatial index will not be used.

When would you use ST_MakeEnvelope?

Use ST_MakeEnvelope to construct a bounding box on the fly for spatial predicates like ST_Intersects, &&, or ST_Contains. It is ubiquitous in map-server backends, where each viewport pan/zoom translates into a query of the form "give me features inside this rectangle":

SQL
1SELECT id, name, geom
2FROM parcels
3WHERE geom && ST_MakeEnvelope(-73.99, 40.74, -73.97, 40.76, 4326);

Also useful for tile rendering (ST_MakeEnvelope plus ST_AsMVTGeom), defining inclusion zones in batch ETL, and clipping imports to a region of interest. The && bbox operator against an envelope is index-accelerated and very fast on large tables with a GiST index on the geometry column.

FAQs

Do I need to pass an SRID?

Technically no, but you almost always should. Without one the envelope has SRID 0, and spatial predicates against an SRID-bound column will either error ("mixed SRIDs") or silently skip the index. Pass the matching SRID as the fifth argument.

What is the difference between ST_MakeEnvelope and ST_Envelope?

ST_MakeEnvelope constructs a bounding-box polygon from four numeric bounds. ST_Envelope takes an existing geometry and returns its axis-aligned bounding box as a polygon. They produce the same kind of output but differ in input.

Is ST_MakeEnvelope suitable for lat/lon queries?

Yes, with the SRID set to 4326. Be aware the envelope does not wrap the antimeridian — a query spanning longitude 179 to -179 does not work correctly; split into two envelopes or use a geography workaround.

Can I build a 3D envelope?

No. ST_MakeEnvelope is strictly 2D. For Z-aware bounding volumes use ST_3DMakeBox and Box3D::geometry casts, though these are less commonly needed.