title_wip

**Syntax**

```
s2RectContains(s2PointLow, s2PointHi, s2Point)
```

**Arguments**

- `s2PointLow` — Low S2 point index corresponding to the rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).
- `s2PointHigh` — High S2 point index corresponding to the rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).
- `s2Point` — Target S2 point index. [UInt64](/docs/sql-reference/data-types/int-uint).

**Returned value**

- `1` — If the rectangle contains the given S2 point.
- `0` — If the rectangle doesn't contain the given S2 point.

**Example**

Query:

```
SELECT s2RectContains(5179062030687166815, 5177056748191934217, 5177914411069187297) AS rectContains;
```

Result:

```
┌─rectContains─┐
│            0 │
└──────────────┘
```

## s2RectUnion[​](#s2rectunion "Direct link to s2RectUnion")

Returns the smallest rectangle containing the union of this rectangle and the given rectangle. In the S2 system, a rectangle is represented by a type of S2Region called a `S2LatLngRect` that represents a rectangle in latitude-longitude space.

**Syntax**

```
s2RectUnion(s2Rect1PointLow, s2Rect1PointHi, s2Rect2PointLow, s2Rect2PointHi)
```

**Arguments**

- `s2Rect1PointLow`, `s2Rect1PointHi` — Low and High S2 point indexes corresponding to the first rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).
- `s2Rect2PointLow`, `s2Rect2PointHi` — Low and High S2 point indexes corresponding to the second rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).

**Returned values**

- `s2UnionRect2PointLow` — Low S2 cell id corresponding to the union rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).
- `s2UnionRect2PointHi` — High S2 cell id corresponding to the union rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).

**Example**

Query:

```
SELECT s2RectUnion(5178914411069187297, 5177056748191934217, 5179062030687166815, 5177056748191934217) AS rectUnion;
```

Result:

```
┌─rectUnion─────────────────────────────────┐
│ (5179062030687166815,5177056748191934217) │
└───────────────────────────────────────────┘
```

## s2RectIntersection[​](#s2rectintersection "Direct link to s2RectIntersection")

Returns the smallest rectangle containing the intersection of this rectangle and the given rectangle. In the S2 system, a rectangle is represented by a type of S2Region called a `S2LatLngRect` that represents a rectangle in latitude-longitude space.

**Syntax**

```
s2RectIntersection(s2Rect1PointLow, s2Rect1PointHi, s2Rect2PointLow, s2Rect2PointHi)
```

**Arguments**

- `s2Rect1PointLow`, `s2Rect1PointHi` — Low and High S2 point indexes corresponding to the first rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).
- `s2Rect2PointLow`, `s2Rect2PointHi` — Low and High S2 point indexes corresponding to the second rectangle. [UInt64](/docs/sql-reference/data-types/int-uint).

**Returned values**

- `s2UnionRect2PointLow` — Low S2 cell id corresponding to the rectangle containing the intersection of the given rectangles. [UInt64](/docs/sql-reference/data-types/int-uint).
- `s2UnionRect2PointHi` — High S2 cell id corresponding to the rectangle containing the intersection of the given rectangles. [UInt64](/docs/sql-reference/data-types/int-uint).

**Example**

Query:

```
SELECT s2RectIntersection(5178914411069187297, 5177056748191934217, 5179062030687166815, 5177056748191934217) AS rectIntersection;
```

Result:

```
┌─rectIntersection──────────────────────────┐
│ (5178914411069187297,5177056748191934217) │
└───────────────────────────────────────────┘
```

- [S2Index](#s2index)- [geoToS2](#geotos2)- [s2ToGeo](#s2togeo)- [s2GetNeighbors](#s2getneighbors)- [s2CellsIntersect](#s2cellsintersect)- [s2CapContains](#s2capcontains)- [s2CapUnion](#s2capunion)- [s2RectAdd](#s2rectadd)- [s2RectContains](#s2rectcontains)- [s2RectUnion](#s2rectunion)- [s2RectIntersection](#s2rectintersection)

Was this page helpful?