ST_Expand
What is ST_Expand?
ST_Expand is a PostGIS function that returns a geometry or box expanded outward by a fixed distance in each coordinate direction. It is effectively the bounding-box equivalent of ST_Buffer and is far cheaper to compute.
1ST_Expand(geometry geom, float units_to_expand) → geometry
2ST_Expand(geometry geom, float dx, float dy) → geometry
3ST_Expand(geometry geom, float dx, float dy, float dz, float dm) → geometry
4ST_Expand(box2d box, float units_to_expand) → box2d
5ST_Expand(box2d box, float dx, float dy) → box2d
6ST_Expand(box3d box, float units_to_expand) → box3d
7ST_Expand(box3d box, float dx, float dy, float dz) → box3dExpansion is applied to the input's bounding box, so the result is always a rectangular/cuboidal geometry (for the geometry overload, a polygon).
When would you use ST_Expand?
Use ST_Expand to grow a search area by a tolerance before running an index-accelerated bounding-box filter — much faster than buffering the geometry itself. It is the canonical companion of ST_DWithin in manual range queries and in tile-generation pipelines where you need a small margin around the viewport.
1SELECT p.id
2FROM pois p
3WHERE p.geom && ST_Expand(ST_MakePoint(-9.14, 38.73)::geometry, 0.01);FAQs
How does ST_Expand differ from ST_Buffer?
ST_Buffer produces an accurate rounded offset geometry, which is expensive. ST_Expand only expands the bounding box, so the result is always a rectangle. Use ST_Expand inside index filters where approximation is fine, and ST_Buffer when you need actual geometric offsets.
What units does the distance use?
The distance is in the units of the geometry's SRS — degrees for EPSG:4326, metres for projected CRSs like UTM. This is the same unit convention as ST_Buffer(geometry, float). There is no geography overload, so for geodesic expansion you must transform to a metric projection first.
Can I expand in only one direction?
Yes — use the per-axis overloads ST_Expand(geom, dx, dy) or ST_Expand(geom, dx, dy, dz, dm) to expand asymmetrically. Setting dy = 0 effectively widens the box only in X.
How does ST_Expand handle empty geometries?
An empty geometry has no bounding box to expand, so ST_Expand returns NULL. Wrap with COALESCE or filter out empties if they appear in your dataset.