> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Box2D Functions

The `Box2D` type in Sedona represents a planar axis-aligned bounding box — a rectangle described by four `Double` values: `xmin`, `ymin`, `xmax`, `ymax`. It is a first-class SQL type backed by a Spark UDT and serializes to a struct of four non-nullable doubles, so columns of `Box2D` round-trip natively through Parquet and align with GeoParquet 1.1 bbox covering columns.

`Box2D` complements the [Geometry](/reference/wherobots-db/geometry-data/geometry-functions) and [Geography](/reference/wherobots-db/geometry-data/geography/geography-functions) types. Use it when you need a compact, comparable bounding rectangle — for example, as a covering column on a GeoParquet table that lets the reader prune row groups, or as the join key in a spatial join that only needs an envelope-level match.

## Semantic notes

* `Box2D` values use closed-interval semantics: edge-touching boxes are considered intersecting and contained (via `ST_Intersects` / `ST_Contains` over `Box2D` inputs).
* Absence is represented by SQL `NULL` rather than an in-band sentinel.
* Bounds are required to be ordered (`xmin <= xmax`, `ymin <= ymax`). Inverted-bound values are reserved for a future antimeridian-wraparound semantics on geography bboxes; predicates and join planning throw `IllegalArgumentException` on inverted input today.
* Unlike [ST\_Envelope](/reference/wherobots-db/geometry-data/bounding-box/ST_Envelope), which returns the envelope as a `Geometry` (typically a polygon, but JTS may return a `Point` or `LineString` for degenerate inputs), [ST\_Box2D](/reference/wherobots-db/geometry-data/box2d/ST_Box2D) always returns a typed `Box2D` value. Prefer the typed form when downstream code only needs the four bounds, and prefer the geometry form when downstream code expects a `Geometry`.

## Constructors

| Function                                                                          | Return type | Description                                                                                               | Since  |
| :-------------------------------------------------------------------------------- | :---------- | :-------------------------------------------------------------------------------------------------------- | :----- |
| [ST\_Box2D](/reference/wherobots-db/geometry-data/box2d/ST_Box2D)                 | Box2D       | Return the planar bounding box of a Geometry as a Box2D.                                                  | v1.9.1 |
| [ST\_MakeBox2D](/reference/wherobots-db/geometry-data/box2d/ST_MakeBox2D)         | Box2D       | Build a Box2D from two corner POINT geometries.                                                           | v1.9.1 |
| [ST\_GeomFromBox2D](/reference/wherobots-db/geometry-data/box2d/ST_GeomFromBox2D) | Geometry    | Convert a Box2D to a closed rectangular polygon Geometry (degenerate boxes return a Point or LineString). | v1.9.1 |

## Accessors

| Function                                                               | Return type | Description                                 | Since  |
| :--------------------------------------------------------------------- | :---------- | :------------------------------------------ | :----- |
| [ST\_XMin](/reference/wherobots-db/geometry-data/bounding-box/ST_XMin) | Double      | Return the minimum X coordinate of a Box2D. | v1.9.1 |
| [ST\_YMin](/reference/wherobots-db/geometry-data/bounding-box/ST_YMin) | Double      | Return the minimum Y coordinate of a Box2D. | v1.9.1 |
| [ST\_XMax](/reference/wherobots-db/geometry-data/bounding-box/ST_XMax) | Double      | Return the maximum X coordinate of a Box2D. | v1.9.1 |
| [ST\_YMax](/reference/wherobots-db/geometry-data/bounding-box/ST_YMax) | Double      | Return the maximum Y coordinate of a Box2D. | v1.9.1 |

The same `ST_XMin` / `ST_YMin` / `ST_XMax` / `ST_YMax` functions also accept `Geometry` inputs — see [Bounding Box Functions](/reference/wherobots-db/geometry-data/geometry-functions#bounding-box-functions).

## Predicates

`Box2D`-on-`Box2D` overlap and containment are expressed through the standard [ST\_Intersects](/reference/wherobots-db/geometry-data/predicates/ST_Intersects) and [ST\_Contains](/reference/wherobots-db/geometry-data/predicates/ST_Contains) predicates, which accept `Box2D` inputs directly with closed-interval semantics (`ST_Intersects` matches PostGIS `&&` and `ST_Contains` matches PostGIS `~` on `box2d`).

| Function                                                                   | Return type | Description                                                        | Since  |
| :------------------------------------------------------------------------- | :---------- | :----------------------------------------------------------------- | :----- |
| [ST\_DWithin](/reference/wherobots-db/geometry-data/predicates/ST_DWithin) | Boolean     | Closed-interval planar distance test between two Box2D rectangles. | v1.9.1 |

## Utility functions

| Function                                                                   | Return type | Description                                                            | Since  |
| :------------------------------------------------------------------------- | :---------- | :--------------------------------------------------------------------- | :----- |
| [ST\_Expand](/reference/wherobots-db/geometry-data/bounding-box/ST_Expand) | Box2D       | Expand a Box2D by a per-axis or uniform delta.                         | v1.9.1 |
| [ST\_AsText](/reference/wherobots-db/geometry-data/output/ST_AsText)       | String      | Return the `BOX(xmin ymin, xmax ymax)` text representation of a Box2D. | v1.9.1 |

## Aggregates

| Function                                                                | Return type | Description                                                                                                                              | Since  |
| :---------------------------------------------------------------------- | :---------- | :--------------------------------------------------------------------------------------------------------------------------------------- | :----- |
| [ST\_Extent](/reference/wherobots-db/geometry-data/aggregate/ST_Extent) | Box2D       | Return the planar bounding box of all geometries in a column as a Box2D. Empty and NULL inputs are skipped. Mirrors PostGIS `ST_Extent`. | v1.9.1 |

## Type conversion

Catalyst recognizes SQL `CAST` between `Box2D` and `Geometry`:

| Cast                    | Equivalent function                                                                    | Notes                                                               |
| :---------------------- | :------------------------------------------------------------------------------------- | :------------------------------------------------------------------ |
| `CAST(geom AS box2d)`   | [ST\_Box2D(geom)](/reference/wherobots-db/geometry-data/box2d/ST_Box2D)                | Planar bounding box of the geometry.                                |
| `CAST(box AS geometry)` | [ST\_GeomFromBox2D(box)](/reference/wherobots-db/geometry-data/box2d/ST_GeomFromBox2D) | Closed rectangular polygon (Point/LineString for degenerate boxes). |

The cast forms require the Sedona SQL parser extension (`spark.sql.extensions=org.apache.sedona.sql.SedonaSqlExtensions`); the function forms work in any Sedona-enabled session.

## Query optimization

Box2D-typed columns are first-class participants in Sedona's spatial optimizer:

* **Filter pushdown.** `ST_Intersects` / `ST_Contains` predicates over a Box2D column and a literal Box2D push down to Parquet row-group statistics on the column's underlying `xmin` / `ymin` / `xmax` / `ymax` leaves. See [Box2D filter pushdown](/reference/wherobots-db/geometry-data/optimizer#box2d-filter-pushdown).
* **Spatial joins.** `ST_Intersects` and `ST_Contains` over two Box2D columns route through the same physical operators (`RangeJoinExec`, `BroadcastIndexJoinExec`) used for `Geometry`. See [Range join](/reference/wherobots-db/geometry-data/optimizer#range-join) and [Broadcast index join](/reference/wherobots-db/geometry-data/optimizer#broadcast-index-join).
