Skip to main content
Converts a Box2D to a closed rectangular polygon Geometry. Equivalent to PostGIS box2d::geometry. Degenerate boxes return the appropriate lower-dimensional geometry:
Box2D shapeReturned geometry
Both axes have non-zero extentPOLYGON (closed rectangle)
One axis collapsed (e.g. xmin == xmax)LINESTRING along the non-collapsed axis
Both axes collapsed (xmin == xmax && ymin == ymax)POINT
It is also produced by the SQL cast CAST(box AS geometry). Returns NULL on NULL input.

Signatures

ST_GeomFromBox2D(box: Box2D)

Parameters

box
Box2D
required
The bounding box to convert to a geometry.

Return type

A closed rectangular polygon (or a lower-dimensional geometry for degenerate boxes).

Example

SELECT ST_AsText(ST_GeomFromBox2D(ST_MakeBox2D(ST_Point(0.0, 0.0), ST_Point(2.0, 4.0))))
POLYGON ((0 0, 0 4, 2 4, 2 0, 0 0))