> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for H3

# Functions for Working with H3 Indexes

<h2 id="h3-index">
  H3 Index
</h2>

[H3](https://h3geo.org/) is a geographical indexing system where the Earth's surface is divided into a grid of even hexagonal cells. This system is hierarchical, i. e. each hexagon on the top level ("parent") can be split into seven even but smaller ones ("children"), and so on.

The level of the hierarchy is called `resolution` and can receive a value from `0` till `15`, where `0` is the `base` level with the largest and coarsest cells.

A latitude and longitude pair can be transformed to a 64-bit H3 index, identifying a grid cell.

The H3 index is used primarily for bucketing locations and other geospatial manipulations.

The full description of the H3 system is available at [the Uber Engineering site](https://www.uber.com/blog/h3/).

<h2 id="h3isvalid">
  h3IsValid
</h2>

Verifies whether the number is a valid [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3IsValid(h3index)
```

**Parameter**

* `h3index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned values**

* 1 — The number is a valid H3 index. [UInt8](/reference/data-types/int-uint).
* 0 — The number is not a valid H3 index. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3IsValid(630814730351855103) AS h3IsValid;
```

```text title="Response" theme={null}
┌─h3IsValid─┐
│         1 │
└───────────┘
```

<h2 id="h3getresolution">
  h3GetResolution
</h2>

Defines the resolution of the given [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3GetResolution(h3index)
```

**Parameter**

* `h3index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned values**

* Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).
* If the index is not valid, the function returns a random value. Use [h3IsValid](#h3isvalid) to verify the index. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3GetResolution(639821929606596015) AS resolution;
```

```text title="Response" theme={null}
┌─resolution─┐
│         14 │
└────────────┘
```

<h2 id="h3edgeangle">
  h3EdgeAngle
</h2>

Calculates the average length of an [H3](#h3-index) hexagon edge in grades.

**Syntax**

```sql theme={null}
h3EdgeAngle(resolution)
```

**Parameter**

* `resolution` — Index resolution. [UInt8](/reference/data-types/int-uint). Range: `[0, 15]`.

**Returned values**

* The average length of an [H3](#h3-index) hexagon edge in grades. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3EdgeAngle(10) AS edgeAngle;
```

```text title="Response" theme={null}
┌───────h3EdgeAngle(10)─┐
│ 0.0005927224846720883 │
└───────────────────────┘
```

<h2 id="h3edgelengthm">
  h3EdgeLengthM
</h2>

Calculates the average length of an [H3](#h3-index) hexagon edge in meters.

**Syntax**

```sql theme={null}
h3EdgeLengthM(resolution)
```

**Parameter**

* `resolution` — Index resolution. [UInt8](/reference/data-types/int-uint). Range: `[0, 15]`.

**Returned values**

* The average edge length of an [H3](#h3-index) hexagon in meters. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3EdgeLengthM(15) AS edgeLengthM;
```

```text title="Response" theme={null}
┌─edgeLengthM─┐
│ 0.509713273 │
└─────────────┘
```

<h2 id="h3edgelengthkm">
  h3EdgeLengthKm
</h2>

Calculates the average length of an [H3](#h3-index) hexagon edge in kilometers.

**Syntax**

```sql theme={null}
h3EdgeLengthKm(resolution)
```

**Parameter**

* `resolution` — Index resolution. [UInt8](/reference/data-types/int-uint). Range: `[0, 15]`.

**Returned values**

* The average length of an [H3](#h3-index) hexagon edge in kilometers. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3EdgeLengthKm(15) AS edgeLengthKm;
```

```text title="Response" theme={null}
┌─edgeLengthKm─┐
│  0.000509713 │
└──────────────┘
```

<h2 id="geotoh3">
  geoToH3
</h2>

Returns [H3](#h3-index) point index `(lat, lon)` with specified resolution.

**Syntax**

```sql theme={null}
geoToH3(lat, lon, resolution)
```

**Arguments**

* `lat` — Latitude. [Float64](/reference/data-types/float).
* `lon` — Longitude. [Float64](/reference/data-types/float).
* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned values**

* Hexagon index number. [UInt64](/reference/data-types/int-uint).
* 0 in case of error. [UInt64](/reference/data-types/int-uint).

Note: In ClickHouse v25.4 or older, `geoToH3()` takes values in order `(lon, lat)`. As per ClickHouse v25.5, the input values are in order `(lat, lon)`. The previous behaviour can be restored using setting `geotoh3_argument_order = 'lon_lat'`.

**Example**

```sql title="Query" theme={null}
SELECT geoToH3(55.71290588, 37.79506683, 15) AS h3Index;
```

```text title="Response" theme={null}
┌────────────h3Index─┐
│ 644325524701193974 │
└────────────────────┘
```

<h2 id="h3togeo">
  h3ToGeo
</h2>

Returns the centroid latitude and longitude corresponding to the provided [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3ToGeo(h3Index)
```

**Arguments**

* `h3Index` — H3 Index. [UInt64](/reference/data-types/int-uint).

**Returned values**

* A tuple consisting of two values: `tuple(lat,lon)`. `lat` — Latitude. [Float64](/reference/data-types/float). `lon` — Longitude. [Float64](/reference/data-types/float).

Note: In ClickHouse v24.12 or older, `h3ToGeo()` returns values in order `(lon, lat)`. As per ClickHouse v25.1, the returned values are in order `(lat, lon)`. The previous behaviour can be restored using setting `h3togeo_lon_lat_result_order = true`.

**Example**

```sql title="Query" theme={null}
SELECT h3ToGeo(644325524701193974) AS coordinates;
```

```text title="Response" theme={null}
┌─coordinates───────────────────────────┐
│ (55.71290243145668,37.79506616830252) │
└───────────────────────────────────────┘
```

<h2 id="h3togeoboundary">
  h3ToGeoBoundary
</h2>

Returns array of pairs `(lat, lon)`, which corresponds to the boundary of the provided H3 index.

**Syntax**

```sql theme={null}
h3ToGeoBoundary(h3Index)
```

**Arguments**

* `h3Index` — H3 Index. [UInt64](/reference/data-types/int-uint).

**Returned values**

* Array of pairs '(lat, lon)'. [Array](/reference/data-types/array)([Float64](/reference/data-types/float), [Float64](/reference/data-types/float)).

**Example**

```sql title="Query" theme={null}
SELECT h3ToGeoBoundary(644325524701193974) AS coordinates;
```

```text title="Response" theme={null}
┌─h3ToGeoBoundary(599686042433355775)────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [(37.2713558667319,-121.91508032705622),(37.353926450852256,-121.8622232890249),(37.42834118609435,-121.92354999630156),(37.42012867767779,-122.03773496427027),(37.33755608435299,-122.090428929044),(37.26319797461824,-122.02910130919001)] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<h2 id="h3kring">
  h3kRing
</h2>

Lists all the [H3](#h3-index) hexagons in the raduis of `k` from the given hexagon in random order.

**Syntax**

```sql theme={null}
h3kRing(h3index, k)
```

**Arguments**

* `h3index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `k` — Radius. [integer](/reference/data-types/int-uint)

**Returned values**

* Array of H3 indexes. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT arrayJoin(h3kRing(644325529233966508, 1)) AS h3index;
```

```text title="Response" theme={null}
┌────────────h3index─┐
│ 644325529233966508 │
│ 644325529233966497 │
│ 644325529233966510 │
│ 644325529233966504 │
│ 644325529233966509 │
│ 644325529233966355 │
│ 644325529233966354 │
└────────────────────┘
```

## h3PolygonToCells

Returns the hexagons (at specified resolution) contained by the provided geometry, either ring or (multi-)polygon.

**Syntax**

```sql theme={null}
h3PolygonToCells(geometry, resolution)
```

**Arguments**

* `geometry` can be one of the following [Geo Data Types](/reference/data-types/geo) or their underlying primitive types:
  * [Ring](/reference/data-types/geo#ring)
  * [Polygon](/reference/data-types/geo#polygon)
  * [MultiPolygon](/reference/data-types/geo#multipolygon)
* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned values**

* Array of the contained H3-indexes. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT h3PolygonToCells([(-122.4089866999972145,37.813318999983238),(-122.3544736999993603,37.7198061999978478),(-122.4798767000009008,37.8151571999998453)], 7) AS h3index;
```

```text title="Response" theme={null}
┌────────────h3index─┐
│ 608692970769612799 │
│ 608692971927240703 │
│ 608692970585063423 │
│ 608692970819944447 │
│ 608692970719281151 │
│ 608692970752835583 │
│ 608692972027903999 │
└────────────────────┘
```

<h2 id="h3polygontocellswithcontainment">
  h3PolygonToCellsWithContainment
</h2>

Returns the hexagons (at specified resolution) covering the provided geometry, either ring or (multi-)polygon, using H3 experimental containment modes.

This function maps `flags` to H3 containment modes:

* `0` — `CONTAINMENT_CENTER`
* `1` — `CONTAINMENT_FULL`
* `2` — `CONTAINMENT_OVERLAPPING`
* `3` — `CONTAINMENT_OVERLAPPING_BBOX`

**Syntax**

```sql theme={null}
h3PolygonToCellsWithContainment(geometry, resolution, flags)
```

**Arguments**

* `geometry` can be one of the following [Geo Data Types](/reference/data-types/geo) or their underlying primitive types:
  * [Ring](/reference/data-types/geo#ring)
  * [Polygon](/reference/data-types/geo#polygon)
  * [MultiPolygon](/reference/data-types/geo#multipolygon)
* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).
* `flags` — Containment mode. Range: `[0, 3]`. Use integer literals such as `0`, `1`, `2`, and `3`, or [UInt32](/reference/data-types/int-uint) values (for example, `toUInt32(2)`). Values are passed to the H3 API as `UInt32`. Other native integer types are converted with an accurate cast.

**Returned values**

* Array of H3-indexes according to the selected containment mode. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT
    h3PolygonToCellsWithContainment([(-122.4089866999972145, 37.813318999983238), (-122.3544736999993603, 37.7198061999978478), (-122.4798767000009008, 37.8151571999998453)], 7, 0) AS center_cells,
    h3PolygonToCellsWithContainment([(-122.4089866999972145, 37.813318999983238), (-122.3544736999993603, 37.7198061999978478), (-122.4798767000009008, 37.8151571999998453)], 7, 2) AS overlap_cells;
```

```text title="Response" theme={null}
   ┌─center_cells───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─overlap_cells──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
1. │ [608692970585063423,608692970719281151,608692970752835583,608692970769612799,608692970819944447,608692971927240703,608692972027903999] │ [608692970249519103,608692970266296319,608692970585063423,608692970601840639,608692970635395071,608692970685726719,608692970719281151,608692970736058367,608692970752835583,608692970769612799,608692970786390015,608692970819944447,608692971927240703,608692971994349567,608692972027903999] │
   └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<h2 id="h3getbasecell">
  h3GetBaseCell
</h2>

Returns the base cell number of the [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3GetBaseCell(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Hexagon base cell number. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3GetBaseCell(612916788725809151) AS basecell;
```

```text title="Response" theme={null}
┌─basecell─┐
│       12 │
└──────────┘
```

<h2 id="h3hexaream2">
  h3HexAreaM2
</h2>

Returns average hexagon area in square meters at the given resolution.

**Syntax**

```sql theme={null}
h3HexAreaM2(resolution)
```

**Parameter**

* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned value**

* Area in square meters. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3HexAreaM2(13) AS area;
```

```text title="Response" theme={null}
┌─area─┐
│ 43.9 │
└──────┘
```

<h2 id="h3hexareakm2">
  h3HexAreaKm2
</h2>

Returns average hexagon area in square kilometers at the given resolution.

**Syntax**

```sql theme={null}
h3HexAreaKm2(resolution)
```

**Parameter**

* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned value**

* Area in square kilometers. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3HexAreaKm2(13) AS area;
```

```text title="Response" theme={null}
┌──────area─┐
│ 0.0000439 │
└───────────┘
```

<h2 id="h3indexesareneighbors">
  h3IndexesAreNeighbors
</h2>

Returns whether or not the provided [H3](#h3-index) indexes are neighbors.

**Syntax**

```sql theme={null}
h3IndexesAreNeighbors(index1, index2)
```

**Arguments**

* `index1` — Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `index2` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* `1` — Indexes are neighbours. [UInt8](/reference/data-types/int-uint).
* `0` — Indexes are not neighbours. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3IndexesAreNeighbors(617420388351344639, 617420388352655359) AS n;
```

```text title="Response" theme={null}
┌─n─┐
│ 1 │
└───┘
```

<h2 id="h3tochildren">
  h3ToChildren
</h2>

Returns an array of child indexes for the given [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3ToChildren(index, resolution)
```

**Arguments**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned values**

* Array of the child H3-indexes. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT h3ToChildren(599405990164561919, 6) AS children;
```

```text title="Response" theme={null}
┌─children───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [603909588852408319,603909588986626047,603909589120843775,603909589255061503,603909589389279231,603909589523496959,603909589657714687] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<h2 id="h3toparent">
  h3ToParent
</h2>

Returns the parent (coarser) index containing the given [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3ToParent(index, resolution)
```

**Arguments**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned value**

* Parent H3 index. [UInt64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3ToParent(599405990164561919, 3) AS parent;
```

```text title="Response" theme={null}
┌─────────────parent─┐
│ 590398848891879423 │
└────────────────────┘
```

<h2 id="h3tostring">
  h3ToString
</h2>

Converts the `H3Index` representation of the index to the string representation.

```sql theme={null}
h3ToString(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* String representation of the H3 index. [String](/reference/data-types/string).

**Example**

```sql title="Query" theme={null}
SELECT h3ToString(617420388352917503) AS h3_string;
```

```text title="Response" theme={null}
┌─h3_string───────┐
│ 89184926cdbffff │
└─────────────────┘
```

<h2 id="stringtoh3">
  stringToH3
</h2>

Converts the string representation to the `H3Index` (UInt64) representation.

**Syntax**

```sql theme={null}
stringToH3(index_str)
```

**Parameter**

* `index_str` — String representation of the H3 index. [String](/reference/data-types/string).

**Returned value**

* Hexagon index number. Returns 0 on error. [UInt64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT stringToH3('89184926cc3ffff') AS index;
```

```text title="Response" theme={null}
┌──────────────index─┐
│ 617420388351344639 │
└────────────────────┘
```

<h2 id="h3getresolution-1">
  h3GetResolution
</h2>

Returns the resolution of the [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3GetResolution(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3GetResolution(617420388352917503) AS res;
```

```text title="Response" theme={null}
┌─res─┐
│   9 │
└─────┘
```

<h2 id="h3isresclassiii">
  h3IsResClassIII
</h2>

Returns whether [H3](#h3-index) index has a resolution with Class III orientation.

**Syntax**

```sql theme={null}
h3IsResClassIII(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* `1` — Index has a resolution with Class III orientation. [UInt8](/reference/data-types/int-uint).
* `0` — Index doesn't have a resolution with Class III orientation. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3IsResClassIII(617420388352917503) AS res;
```

```text title="Response" theme={null}
┌─res─┐
│   1 │
└─────┘
```

<h2 id="h3ispentagon">
  h3IsPentagon
</h2>

Returns whether this [H3](#h3-index) index represents a pentagonal cell.

**Syntax**

```sql theme={null}
h3IsPentagon(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* `1` — Index represents a pentagonal cell. [UInt8](/reference/data-types/int-uint).
* `0` — Index doesn't represent a pentagonal cell. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3IsPentagon(644721767722457330) AS pentagon;
```

```text title="Response" theme={null}
┌─pentagon─┐
│        0 │
└──────────┘
```

<h2 id="h3getfaces">
  h3GetFaces
</h2>

Returns icosahedron faces intersected by a given [H3](#h3-index) index.

**Syntax**

```sql theme={null}
h3GetFaces(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned values**

* Array containing icosahedron faces intersected by a given H3 index. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT h3GetFaces(599686042433355775) AS faces;
```

```text title="Response" theme={null}
┌─faces─┐
│ [7]   │
└───────┘
```

<h2 id="h3cellaream2">
  h3CellAreaM2
</h2>

Returns the exact area of a specific cell in square meters corresponding to the given input H3 index.

**Syntax**

```sql theme={null}
h3CellAreaM2(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Cell area in square meters. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3CellAreaM2(579205133326352383) AS area;
```

```text title="Response" theme={null}
┌───────────────area─┐
│ 4106166334463.9233 │
└────────────────────┘
```

<h2 id="h3cellarearads2">
  h3CellAreaRads2
</h2>

Returns the exact area of a specific cell in square radians corresponding to the given input H3 index.

**Syntax**

```sql theme={null}
h3CellAreaRads2(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Cell area in square radians. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3CellAreaRads2(579205133326352383) AS area;
```

```text title="Response" theme={null}
┌────────────────area─┐
│ 0.10116268528089567 │
└─────────────────────┘
```

<h2 id="h3tocenterchild">
  h3ToCenterChild
</h2>

Returns the center child (finer) [H3](#h3-index) index contained by given [H3](#h3-index) at the given resolution.

**Syntax**

```sql theme={null}
h3ToCenterChild(index, resolution)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned values**

* [H3](#h3-index) index of the center child contained by given [H3](#h3-index) at the given resolution. [UInt64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3ToCenterChild(577023702256844799,1) AS centerToChild;
```

```text title="Response" theme={null}
┌──────centerToChild─┐
│ 581496515558637567 │
└────────────────────┘
```

<h2 id="h3exactedgelengthm">
  h3ExactEdgeLengthM
</h2>

Returns the exact edge length of the unidirectional edge represented by the input h3 index in meters.

**Syntax**

```sql theme={null}
h3ExactEdgeLengthM(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Exact edge length in meters. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3ExactEdgeLengthM(1310277011704381439) AS exactEdgeLengthM;;
```

```text title="Response" theme={null}
┌───exactEdgeLengthM─┐
│ 195449.63163407316 │
└────────────────────┘
```

<h2 id="h3exactedgelengthkm">
  h3ExactEdgeLengthKm
</h2>

Returns the exact edge length of the unidirectional edge represented by the input h3 index in kilometers.

**Syntax**

```sql theme={null}
h3ExactEdgeLengthKm(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Exact edge length in kilometers. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3ExactEdgeLengthKm(1310277011704381439) AS exactEdgeLengthKm;;
```

```text title="Response" theme={null}
┌──exactEdgeLengthKm─┐
│ 195.44963163407317 │
└────────────────────┘
```

<h2 id="h3exactedgelengthrads">
  h3ExactEdgeLengthRads
</h2>

Returns the exact edge length of the unidirectional edge represented by the input h3 index in radians.

**Syntax**

```sql theme={null}
h3ExactEdgeLengthRads(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Exact edge length in radians. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3ExactEdgeLengthRads(1310277011704381439) AS exactEdgeLengthRads;;
```

```text title="Response" theme={null}
┌──exactEdgeLengthRads─┐
│ 0.030677980118976447 │
└──────────────────────┘
```

<h2 id="h3numhexagons">
  h3NumHexagons
</h2>

Returns the number of unique H3 indices at the given resolution.

**Syntax**

```sql theme={null}
h3NumHexagons(resolution)
```

**Parameter**

* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned value**

* Number of H3 indices. [Int64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
SELECT h3NumHexagons(3) AS numHexagons;
```

```text title="Response" theme={null}
┌─numHexagons─┐
│       41162 │
└─────────────┘
```

<h2 id="h3pointdistm">
  h3PointDistM
</h2>

Returns the "great circle" or "haversine" distance between pairs of GeoCoord points (latitude/longitude) pairs in meters.

**Syntax**

```sql theme={null}
h3PointDistM(lat1, lon1, lat2, lon2)
```

**Arguments**

* `lat1`, `lon1` — Latitude and Longitude of point1 in degrees. [Float64](/reference/data-types/float).
* `lat2`, `lon2` — Latitude and Longitude of point2 in degrees. [Float64](/reference/data-types/float).

**Returned values**

* Haversine or great circle distance in meters.[Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3PointDistM(-10.0 ,0.0, 10.0, 0.0) AS h3PointDistM;
```

```text title="Response" theme={null}
┌──────h3PointDistM─┐
│ 2223901.039504589 │
└───────────────────┘
```

<h2 id="h3pointdistkm">
  h3PointDistKm
</h2>

Returns the "great circle" or "haversine" distance between pairs of GeoCoord points (latitude/longitude) pairs in kilometers.

**Syntax**

```sql theme={null}
h3PointDistKm(lat1, lon1, lat2, lon2)
```

**Arguments**

* `lat1`, `lon1` — Latitude and Longitude of point1 in degrees. [Float64](/reference/data-types/float).
* `lat2`, `lon2` — Latitude and Longitude of point2 in degrees. [Float64](/reference/data-types/float).

**Returned values**

* Haversine or great circle distance in kilometers. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3PointDistKm(-10.0 ,0.0, 10.0, 0.0) AS h3PointDistKm;
```

```text title="Response" theme={null}
┌─────h3PointDistKm─┐
│ 2223.901039504589 │
└───────────────────┘
```

<h2 id="h3pointdistrads">
  h3PointDistRads
</h2>

Returns the "great circle" or "haversine" distance between pairs of GeoCoord points (latitude/longitude) pairs in radians.

**Syntax**

```sql theme={null}
h3PointDistRads(lat1, lon1, lat2, lon2)
```

**Arguments**

* `lat1`, `lon1` — Latitude and Longitude of point1 in degrees. [Float64](/reference/data-types/float).
* `lat2`, `lon2` — Latitude and Longitude of point2 in degrees. [Float64](/reference/data-types/float).

**Returned values**

* Haversine or great circle distance in radians. [Float64](/reference/data-types/float).

**Example**

```sql title="Query" theme={null}
SELECT h3PointDistRads(-10.0 ,0.0, 10.0, 0.0) AS h3PointDistRads;
```

```text title="Response" theme={null}
┌────h3PointDistRads─┐
│ 0.3490658503988659 │
└────────────────────┘
```

<h2 id="h3getres0indexes">
  h3GetRes0Indexes
</h2>

Returns an array of all the resolution 0 H3 indexes.

**Syntax**

```sql theme={null}
h3GetRes0Indexes()
```

**Returned values**

* Array of all the resolution 0 H3 indexes. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT h3GetRes0Indexes AS indexes ;
```

```text title="Response" theme={null}
┌─indexes─────────────────────────────────────┐
│ [576495936675512319,576531121047601151,....]│
└─────────────────────────────────────────────┘
```

<h2 id="h3getpentagonindexes">
  h3GetPentagonIndexes
</h2>

Returns all the pentagon H3 indexes at the specified resolution.

**Syntax**

```sql theme={null}
h3GetPentagonIndexes(resolution)
```

**Parameter**

* `resolution` — Index resolution. Range: `[0, 15]`. [UInt8](/reference/data-types/int-uint).

**Returned value**

* Array of all pentagon H3 indexes. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
SELECT h3GetPentagonIndexes(3) AS indexes;
```

```text title="Response" theme={null}
┌─indexes────────────────────────────────────────────────────────┐
│ [590112357393367039,590464201114255359,590816044835143679,...] │
└────────────────────────────────────────────────────────────────┘
```

<h2 id="h3line">
  h3Line
</h2>

Returns the line of indices between the two indices that are provided.

**Syntax**

```sql theme={null}
h3Line(start,end)
```

**Parameter**

* `start` — Hexagon index number that represents a starting point. [UInt64](/reference/data-types/int-uint).
* `end` — Hexagon index number that represents an ending point. [UInt64](/reference/data-types/int-uint).

**Returned value**

Array of h3 indexes representing the line of indices between the two provided indices. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
 SELECT h3Line(590080540275638271,590103561300344831) AS indexes;
```

```text title="Response" theme={null}
┌─indexes────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [590080540275638271,590080471556161535,590080883873021951,590106516237844479,590104385934065663,590103630019821567,590103561300344831] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<h2 id="h3distance">
  h3Distance
</h2>

Returns the distance in grid cells between the two indices that are provided.

**Syntax**

```sql theme={null}
h3Distance(start,end)
```

**Parameter**

* `start` — Hexagon index number that represents a starting point. [UInt64](/reference/data-types/int-uint).
* `end` — Hexagon index number that represents an ending point. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Number of grid cells. [Int64](/reference/data-types/int-uint).

Returns a negative number if finding the distance fails.

**Example**

```sql title="Query" theme={null}
 SELECT h3Distance(590080540275638271,590103561300344831) AS distance;
```

```text title="Response" theme={null}
┌─distance─┐
│        7 │
└──────────┘
```

<h2 id="h3hexring">
  h3HexRing
</h2>

Returns the indexes of the hexagonal ring centered at the provided origin h3Index and length k.

Returns 0 if no pentagonal distortion was encountered.

**Syntax**

```sql theme={null}
h3HexRing(index, k)
```

**Parameter**

* `index` — Hexagon index number that represents the origin. [UInt64](/reference/data-types/int-uint).
* `k` — Distance. [UInt64](/reference/data-types/int-uint).

**Returned values**

* Array of H3 indexes. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
 SELECT h3HexRing(590080540275638271, toUInt16(1)) AS hexRing;
```

```text title="Response" theme={null}
┌─hexRing─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [590080815153545215,590080471556161535,590080677714591743,590077585338138623,590077447899185151,590079509483487231] │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<h2 id="h3getunidirectionaledge">
  h3GetUnidirectionalEdge
</h2>

Returns a unidirectional edge H3 index based on the provided origin and destination and returns 0 on error.

**Syntax**

```sql theme={null}
h3GetUnidirectionalEdge(originIndex, destinationIndex)
```

**Parameter**

* `originIndex` — Origin Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `destinationIndex` — Destination Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Unidirectional Edge Hexagon Index number. [UInt64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
 SELECT h3GetUnidirectionalEdge(599686042433355775, 599686043507097599) AS edge;
```

```text title="Response" theme={null}
┌────────────────edge─┐
│ 1248204388774707199 │
└─────────────────────┘
```

<h2 id="h3unidirectionaledgeisvalid">
  h3UnidirectionalEdgeIsValid
</h2>

Determines if the provided H3Index is a valid unidirectional edge index. Returns 1 if it's a unidirectional edge and 0 otherwise.

**Syntax**

```sql theme={null}
h3UnidirectionalEdgeisValid(index)
```

**Parameter**

* `index` — Hexagon index number. [UInt64](/reference/data-types/int-uint).

**Returned value**

* 1 — The H3 index is a valid unidirectional edge. [UInt8](/reference/data-types/int-uint).
* 0 — The H3 index is not a valid unidirectional edge. [UInt8](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
 SELECT h3UnidirectionalEdgeIsValid(1248204388774707199) AS validOrNot;
```

```text title="Response" theme={null}
┌─validOrNot─┐
│          1 │
└────────────┘
```

<h2 id="h3getoriginindexfromunidirectionaledge">
  h3GetOriginIndexFromUnidirectionalEdge
</h2>

Returns the origin hexagon index from the unidirectional edge H3Index.

**Syntax**

```sql theme={null}
h3GetOriginIndexFromUnidirectionalEdge(edge)
```

**Parameter**

* `edge` — Hexagon index number that represents a unidirectional edge. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Origin Hexagon Index number. [UInt64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
 SELECT h3GetOriginIndexFromUnidirectionalEdge(1248204388774707197) AS origin;
```

```text title="Response" theme={null}
┌─────────────origin─┐
│ 599686042433355773 │
└────────────────────┘
```

<h2 id="h3getdestinationindexfromunidirectionaledge">
  h3GetDestinationIndexFromUnidirectionalEdge
</h2>

Returns the destination hexagon index from the unidirectional edge H3Index.

**Syntax**

```sql theme={null}
h3GetDestinationIndexFromUnidirectionalEdge(edge)
```

**Parameter**

* `edge` — Hexagon index number that represents a unidirectional edge. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Destination Hexagon Index number. [UInt64](/reference/data-types/int-uint).

**Example**

```sql title="Query" theme={null}
 SELECT h3GetDestinationIndexFromUnidirectionalEdge(1248204388774707197) AS destination;
```

```text title="Response" theme={null}
┌────────destination─┐
│ 599686043507097597 │
└────────────────────┘
```

<h2 id="h3getindexesfromunidirectionaledge">
  h3GetIndexesFromUnidirectionalEdge
</h2>

Returns the origin and destination hexagon indexes from the given unidirectional edge H3Index.

**Syntax**

```sql theme={null}
h3GetIndexesFromUnidirectionalEdge(edge)
```

**Parameter**

* `edge` — Hexagon index number that represents a unidirectional edge. [UInt64](/reference/data-types/int-uint).

**Returned value**

A tuple consisting of two values `tuple(origin,destination)`:

* `origin` — Origin Hexagon index number. [UInt64](/reference/data-types/int-uint).
* `destination` — Destination Hexagon index number. [UInt64](/reference/data-types/int-uint).

Returns `(0,0)` if the provided input is not valid.

**Example**

```sql title="Query" theme={null}
 SELECT h3GetIndexesFromUnidirectionalEdge(1248204388774707199) AS indexes;
```

```text title="Response" theme={null}
┌─indexes─────────────────────────────────┐
│ (599686042433355775,599686043507097599) │
└─────────────────────────────────────────┘
```

<h2 id="h3getunidirectionaledgesfromhexagon">
  h3GetUnidirectionalEdgesFromHexagon
</h2>

Provides all of the unidirectional edges from the provided H3Index.

**Syntax**

```sql theme={null}
h3GetUnidirectionalEdgesFromHexagon(index)
```

**Parameter**

* `index` — Hexagon index number that represents a unidirectional edge. [UInt64](/reference/data-types/int-uint).

**Returned value**

Array of h3 indexes representing each unidirectional edge. [Array](/reference/data-types/array)([UInt64](/reference/data-types/int-uint)).

**Example**

```sql title="Query" theme={null}
 SELECT h3GetUnidirectionalEdgesFromHexagon(1248204388774707199) AS edges;
```

```text title="Response" theme={null}
┌─edges─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [1248204388774707199,1320261982812635135,1392319576850563071,1464377170888491007,1536434764926418943,1608492358964346879] │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<h2 id="h3getunidirectionaledgeboundary">
  h3GetUnidirectionalEdgeBoundary
</h2>

Returns the coordinates defining the unidirectional edge.

**Syntax**

```sql theme={null}
h3GetUnidirectionalEdgeBoundary(index)
```

**Parameter**

* `index` — Hexagon index number that represents a unidirectional edge. [UInt64](/reference/data-types/int-uint).

**Returned value**

* Array of pairs '(lon, lat)'. [Array](/reference/data-types/array)([Float64](/reference/data-types/float), [Float64](/reference/data-types/float)).

**Example**

```sql title="Query" theme={null}
 SELECT h3GetUnidirectionalEdgeBoundary(1248204388774707199) AS boundary;
```

```text title="Response" theme={null}
┌─boundary────────────────────────────────────────────────────────────────────────┐
│ [(37.42012867767779,-122.03773496427027),(37.33755608435299,-122.090428929044)] │
└─────────────────────────────────────────────────────────────────────────────────┘
```
