ST_GeomFromBox2D

Introduction: Convert 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

Format: ST_GeomFromBox2D(box: Box2D)

Return type: Geometry

Since: v1.9.1

SQL Example

SELECT ST_AsText(ST_GeomFromBox2D(ST_MakeBox2D(ST_Point(0.0, 0.0), ST_Point(2.0, 4.0))))

Output:

POLYGON ((0 0, 0 4, 2 4, 2 0, 0 0))

ST_GeomFromBox2D is also produced by the SQL cast CAST(box AS geometry) — see Type conversion.

Returns NULL on NULL input.