2020-07-28 07:57:28 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/functions/geo/h3
2022-04-09 13:29:05 +00:00
sidebar_label: H3 Indexes
2022-08-29 16:19:50 +00:00
title: "Functions for Working with H3 Indexes"
2020-07-28 07:57:28 +00:00
---
2024-06-12 13:09:50 +00:00
## H3 Index
2024-06-12 12:09:37 +00:00
2022-06-02 13:01:59 +00:00
[H3 ](https://eng.uber.com/h3/ ) is a geographical indexing system where Earth’ s surface 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.
2020-07-28 07:57:28 +00:00
2021-07-29 15:20:55 +00:00
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.
2020-07-28 07:57:28 +00:00
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.
2023-06-02 11:30:05 +00:00
The full description of the H3 system is available at [the Uber Engineering site ](https://eng.uber.com/h3/ ).
2020-07-28 07:57:28 +00:00
2022-06-02 10:55:18 +00:00
## h3IsValid
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Verifies whether the number is a valid [H3 ](#h3-index ) index.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3IsValid(h3index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `h3index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- 1 — The number is a valid H3 index. [UInt8 ](../../data-types/int-uint.md ).
- 0 — The number is not a valid H3 index. [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-07 16:09:40 +00:00
SELECT h3IsValid(630814730351855103) AS h3IsValid;
2020-07-28 07:57:28 +00:00
```
2021-03-13 18:18:45 +00:00
2020-07-28 07:57:28 +00:00
Result:
``` text
┌─h3IsValid─┐
│ 1 │
└───────────┘
```
2022-06-02 10:55:18 +00:00
## h3GetResolution
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Defines the resolution of the given [H3 ](#h3-index ) index.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3GetResolution(h3index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `h3index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
- If the index is not valid, the function returns a random value. Use [h3IsValid ](#h3isvalid ) to verify the index. [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-07 16:09:40 +00:00
SELECT h3GetResolution(639821929606596015) AS resolution;
2020-07-28 07:57:28 +00:00
```
2021-03-13 18:18:45 +00:00
2020-07-28 07:57:28 +00:00
Result:
``` text
┌─resolution─┐
│ 14 │
└────────────┘
```
2022-06-02 10:55:18 +00:00
## h3EdgeAngle
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Calculates the average length of the [H3 ](#h3-index ) hexagon edge in grades.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3EdgeAngle(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. [UInt8 ](../../data-types/int-uint.md ). Range: `[0, 15]` .
2020-07-28 07:57:28 +00:00
**Returned values**
2024-06-12 13:09:50 +00:00
- The average length of the [H3 ](#h3-index ) hexagon edge in grades. [Float64 ](../../data-types/float.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-07 16:09:40 +00:00
SELECT h3EdgeAngle(10) AS edgeAngle;
2020-07-28 07:57:28 +00:00
```
2021-03-13 18:18:45 +00:00
2020-07-28 07:57:28 +00:00
Result:
``` text
┌───────h3EdgeAngle(10)─┐
│ 0.0005927224846720883 │
└───────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3EdgeLengthM
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Calculates the average length of the [H3 ](#h3-index ) hexagon edge in meters.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3EdgeLengthM(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. [UInt8 ](../../data-types/int-uint.md ). Range: `[0, 15]` .
2020-07-28 07:57:28 +00:00
**Returned values**
2024-06-12 13:09:50 +00:00
- The average length of the [H3 ](#h3-index ) hexagon edge in meters. [Float64 ](../../data-types/float.md ).
2020-07-28 07:57:28 +00:00
**Example**
2021-07-29 15:20:55 +00:00
Query:
2020-07-28 07:57:28 +00:00
``` sql
2021-10-07 16:09:40 +00:00
SELECT h3EdgeLengthM(15) AS edgeLengthM;
2020-07-28 07:57:28 +00:00
```
2021-03-13 18:18:45 +00:00
2020-07-28 07:57:28 +00:00
Result:
``` text
┌─edgeLengthM─┐
│ 0.509713273 │
└─────────────┘
```
2022-06-02 10:55:18 +00:00
## h3EdgeLengthKm
2022-01-11 04:17:28 +00:00
2024-06-12 13:09:50 +00:00
Calculates the average length of the [H3 ](#h3-index ) hexagon edge in kilometers.
2022-01-11 04:17:28 +00:00
**Syntax**
``` sql
h3EdgeLengthKm(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. [UInt8 ](../../data-types/int-uint.md ). Range: `[0, 15]` .
2022-01-11 04:17:28 +00:00
**Returned values**
2024-06-12 13:09:50 +00:00
- The average length of the [H3 ](#h3-index ) hexagon edge in kilometers. [Float64 ](../../data-types/float.md ).
2022-01-11 04:17:28 +00:00
**Example**
Query:
``` sql
SELECT h3EdgeLengthKm(15) AS edgeLengthKm;
```
Result:
``` text
┌─edgeLengthKm─┐
│ 0.000509713 │
└──────────────┘
```
2022-06-02 10:55:18 +00:00
## geoToH3
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Returns [H3 ](#h3-index ) point index `(lon, lat)` with specified resolution.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
geoToH3(lon, lat, resolution)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-07-28 07:57:28 +00:00
2024-05-24 03:54:16 +00:00
- `lon` — Longitude. [Float64 ](../../data-types/float.md ).
- `lat` — Latitude. [Float64 ](../../data-types/float.md ).
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- 0 in case of error. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-07 16:09:40 +00:00
SELECT geoToH3(37.79506683, 55.71290588, 15) AS h3Index;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌────────────h3Index─┐
│ 644325524701193974 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3ToGeo
2021-06-22 14:28:45 +00:00
2024-06-12 13:09:50 +00:00
Returns the centroid longitude and latitude corresponding to the provided [H3 ](#h3-index ) index.
2021-06-22 14:28:45 +00:00
**Syntax**
``` sql
h3ToGeo(h3Index)
```
**Arguments**
2024-05-24 03:54:16 +00:00
- `h3Index` — H3 Index. [UInt64 ](../../data-types/int-uint.md ).
2021-06-22 14:28:45 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- A tuple consisting of two values: `tuple(lon,lat)` . `lon` — Longitude. [Float64 ](../../data-types/float.md ). `lat` — Latitude. [Float64 ](../../data-types/float.md ).
2021-06-22 14:28:45 +00:00
**Example**
Query:
``` sql
2021-07-28 19:07:41 +00:00
SELECT h3ToGeo(644325524701193974) AS coordinates;
2021-06-22 14:28:45 +00:00
```
Result:
``` text
┌─coordinates───────────────────────────┐
│ (37.79506616830252,55.71290243145668) │
└───────────────────────────────────────┘
2021-09-12 20:46:17 +00:00
```
2022-06-02 10:55:18 +00:00
## h3ToGeoBoundary
2021-09-12 20:46:17 +00:00
Returns array of pairs `(lon, lat)` , which corresponds to the boundary of the provided H3 index.
**Syntax**
``` sql
h3ToGeoBoundary(h3Index)
```
**Arguments**
2024-05-24 03:54:16 +00:00
- `h3Index` — H3 Index. [UInt64 ](../../data-types/int-uint.md ).
2021-09-12 20:46:17 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Array of pairs '(lon, lat)'. [Array ](../../data-types/array.md )([Float64](../../data-types/float.md), [Float64 ](../../data-types/float.md )).
2021-09-12 20:46:17 +00:00
**Example**
Query:
``` sql
SELECT h3ToGeoBoundary(644325524701193974) AS coordinates;
```
Result:
``` text
┌─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)] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
2021-06-22 14:28:45 +00:00
```
2021-07-28 19:07:41 +00:00
2022-06-02 10:55:18 +00:00
## h3kRing
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Lists all the [H3 ](#h3-index ) hexagons in the raduis of `k` from the given hexagon in random order.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3kRing(h3index, k)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-07-28 07:57:28 +00:00
2024-05-24 03:54:16 +00:00
- `h3index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `k` — Radius. [integer ](../../data-types/int-uint.md )
2020-07-28 07:57:28 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Array of H3 indexes. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-03-13 18:18:45 +00:00
SELECT arrayJoin(h3kRing(644325529233966508, 1)) AS h3index;
2020-07-28 07:57:28 +00:00
```
2021-03-13 18:18:45 +00:00
2020-07-28 07:57:28 +00:00
Result:
``` text
┌────────────h3index─┐
│ 644325529233966508 │
│ 644325529233966497 │
│ 644325529233966510 │
│ 644325529233966504 │
│ 644325529233966509 │
│ 644325529233966355 │
│ 644325529233966354 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3GetBaseCell
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Returns the base cell number of the [H3 ](#h3-index ) index.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3GetBaseCell(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Hexagon base cell number. [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-07 16:09:40 +00:00
SELECT h3GetBaseCell(612916788725809151) AS basecell;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌─basecell─┐
│ 12 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## h3HexAreaM2
2020-07-28 07:57:28 +00:00
Returns average hexagon area in square meters at the given resolution.
**Syntax**
``` sql
h3HexAreaM2(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Area in square meters. [Float64 ](../../data-types/float.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-07 16:09:40 +00:00
SELECT h3HexAreaM2(13) AS area;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌─area─┐
│ 43.9 │
└──────┘
```
2022-06-02 10:55:18 +00:00
## h3HexAreaKm2
2022-01-08 17:19:17 +00:00
Returns average hexagon area in square kilometers at the given resolution.
**Syntax**
``` sql
h3HexAreaKm2(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2022-01-08 17:19:17 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Area in square kilometers. [Float64 ](../../data-types/float.md ).
2022-01-08 17:19:17 +00:00
**Example**
Query:
``` sql
SELECT h3HexAreaKm2(13) AS area;
```
Result:
``` text
┌──────area─┐
│ 0.0000439 │
└───────────┘
```
2022-06-02 10:55:18 +00:00
## h3IndexesAreNeighbors
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Returns whether or not the provided [H3 ](#h3-index ) indexes are neighbors.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3IndexesAreNeighbors(index1, index2)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-07-28 07:57:28 +00:00
2024-05-24 03:54:16 +00:00
- `index1` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `index2` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- `1` — Indexes are neighbours. [UInt8 ](../../data-types/int-uint.md ).
- `0` — Indexes are not neighbours. [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
SELECT h3IndexesAreNeighbors(617420388351344639, 617420388352655359) AS n;
```
Result:
``` text
┌─n─┐
│ 1 │
└───┘
```
2022-06-02 10:55:18 +00:00
## h3ToChildren
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Returns an array of child indexes for the given [H3 ](#h3-index ) index.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3ToChildren(index, resolution)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-07-28 07:57:28 +00:00
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Array of the child H3-indexes. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
SELECT h3ToChildren(599405990164561919, 6) AS children;
```
Result:
``` text
┌─children───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [603909588852408319,603909588986626047,603909589120843775,603909589255061503,603909589389279231,603909589523496959,603909589657714687] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3ToParent
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Returns the parent (coarser) index containing the given [H3 ](#h3-index ) index.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3ToParent(index, resolution)
```
2021-02-15 21:22:10 +00:00
**Arguments**
2020-07-28 07:57:28 +00:00
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Parent H3 index. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT h3ToParent(599405990164561919, 3) AS parent;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌─────────────parent─┐
│ 590398848891879423 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3ToString
2020-07-28 07:57:28 +00:00
Converts the `H3Index` representation of the index to the string representation.
``` sql
h3ToString(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- String representation of the H3 index. [String ](../../data-types/string.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT h3ToString(617420388352917503) AS h3_string;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌─h3_string───────┐
│ 89184926cdbffff │
└─────────────────┘
```
2022-06-02 10:55:18 +00:00
## stringToH3
2020-07-28 07:57:28 +00:00
Converts the string representation to the `H3Index` (UInt64) representation.
**Syntax**
``` sql
stringToH3(index_str)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index_str` — String representation of the H3 index. [String ](../../data-types/string.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Hexagon index number. Returns 0 on error. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT stringToH3('89184926cc3ffff') AS index;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌──────────────index─┐
│ 617420388351344639 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3GetResolution
2020-07-28 07:57:28 +00:00
2024-06-12 13:09:50 +00:00
Returns the resolution of the [H3 ](#h3-index ) index.
2020-07-28 07:57:28 +00:00
**Syntax**
``` sql
h3GetResolution(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2020-07-28 07:57:28 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT h3GetResolution(617420388352917503) AS res;
2020-07-28 07:57:28 +00:00
```
Result:
``` text
┌─res─┐
│ 9 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## h3IsResClassIII
2021-09-21 23:52:47 +00:00
2024-06-12 13:09:50 +00:00
Returns whether [H3 ](#h3-index ) index has a resolution with Class III orientation.
2021-09-21 23:52:47 +00:00
**Syntax**
``` sql
2021-09-25 17:15:12 +00:00
h3IsResClassIII(index)
2021-09-21 23:52:47 +00:00
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2021-09-21 23:52:47 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- `1` — Index has a resolution with Class III orientation. [UInt8 ](../../data-types/int-uint.md ).
- `0` — Index doesn't have a resolution with Class III orientation. [UInt8 ](../../data-types/int-uint.md ).
2021-09-21 23:52:47 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT h3IsResClassIII(617420388352917503) AS res;
2021-09-21 23:52:47 +00:00
```
Result:
``` text
┌─res─┐
│ 1 │
└─────┘
```
2022-06-02 10:55:18 +00:00
## h3IsPentagon
2021-09-22 00:01:40 +00:00
2024-06-12 13:09:50 +00:00
Returns whether this [H3 ](#h3-index ) index represents a pentagonal cell.
2021-09-22 00:01:40 +00:00
**Syntax**
``` sql
h3IsPentagon(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2021-09-22 00:01:40 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- `1` — Index represents a pentagonal cell. [UInt8 ](../../data-types/int-uint.md ).
- `0` — Index doesn't represent a pentagonal cell. [UInt8 ](../../data-types/int-uint.md ).
2021-09-22 00:01:40 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT h3IsPentagon(644721767722457330) AS pentagon;
2021-09-22 00:01:40 +00:00
```
Result:
``` text
┌─pentagon─┐
│ 0 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## h3GetFaces
2021-09-22 00:41:28 +00:00
2024-06-12 13:09:50 +00:00
Returns icosahedron faces intersected by a given [H3 ](#h3-index ) index.
2021-09-22 00:41:28 +00:00
**Syntax**
``` sql
h3GetFaces(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2021-09-22 00:41:28 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Array containing icosahedron faces intersected by a given H3 index. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2021-09-22 00:41:28 +00:00
**Example**
Query:
``` sql
2021-10-05 19:12:44 +00:00
SELECT h3GetFaces(599686042433355775) AS faces;
2021-09-22 00:41:28 +00:00
```
Result:
``` text
┌─faces─┐
│ [7] │
└───────┘
```
2022-06-02 10:55:18 +00:00
## h3CellAreaM2
2022-01-08 16:48:54 +00:00
2022-01-08 18:40:38 +00:00
Returns the exact area of a specific cell in square meters corresponding to the given input H3 index.
2022-01-08 16:48:54 +00:00
**Syntax**
``` sql
2022-01-08 18:40:38 +00:00
h3CellAreaM2(index)
2022-01-08 16:48:54 +00:00
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-01-08 16:51:35 +00:00
2022-01-08 18:40:38 +00:00
**Returned value**
2022-01-08 16:51:35 +00:00
2024-05-24 03:54:16 +00:00
- Cell area in square meters. [Float64 ](../../data-types/float.md ).
2022-01-08 16:51:35 +00:00
**Example**
Query:
``` sql
2022-01-08 18:40:38 +00:00
SELECT h3CellAreaM2(579205133326352383) AS area;
2022-01-08 16:51:35 +00:00
```
Result:
``` text
2022-01-08 18:40:38 +00:00
┌───────────────area─┐
│ 4106166334463.9233 │
└────────────────────┘
2022-01-08 16:51:35 +00:00
```
2022-06-02 10:55:18 +00:00
## h3CellAreaRads2
2022-01-08 18:40:38 +00:00
2022-01-08 23:23:15 +00:00
Returns the exact area of a specific cell in square radians corresponding to the given input H3 index.
2022-01-08 18:40:38 +00:00
**Syntax**
``` sql
2022-01-08 23:23:15 +00:00
h3CellAreaRads2(index)
2022-01-08 18:40:38 +00:00
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-01-08 18:40:38 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Cell area in square radians. [Float64 ](../../data-types/float.md ).
2022-01-08 18:40:38 +00:00
**Example**
Query:
``` sql
2022-01-08 23:23:15 +00:00
SELECT h3CellAreaRads2(579205133326352383) AS area;
2022-01-08 18:40:38 +00:00
```
Result:
``` text
2022-01-08 23:23:15 +00:00
┌────────────────area─┐
│ 0.10116268528089567 │
└─────────────────────┘
2022-01-08 18:40:38 +00:00
```
2022-06-02 10:55:18 +00:00
## h3ToCenterChild
2022-01-08 23:23:15 +00:00
2024-06-12 13:09:50 +00:00
Returns the center child (finer) [H3 ](#h3-index ) index contained by given [H3 ](#h3-index ) at the given resolution.
2022-01-08 23:23:15 +00:00
**Syntax**
``` sql
2022-01-19 13:04:23 +00:00
h3ToCenterChild(index, resolution)
2022-01-08 23:23:15 +00:00
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2022-01-08 23:23:15 +00:00
2022-01-19 13:04:23 +00:00
**Returned values**
2022-01-08 23:23:15 +00:00
2024-06-12 13:09:50 +00:00
- [H3 ](#h3-index ) index of the center child contained by given [H3 ](#h3-index ) at the given resolution. [UInt64 ](../../data-types/int-uint.md ).
2022-01-08 23:23:15 +00:00
**Example**
Query:
``` sql
2022-01-19 13:04:23 +00:00
SELECT h3ToCenterChild(577023702256844799,1) AS centerToChild;
2022-01-08 23:23:15 +00:00
```
Result:
``` text
2022-01-19 13:04:23 +00:00
┌──────centerToChild─┐
│ 581496515558637567 │
└────────────────────┘
2022-01-08 23:23:15 +00:00
```
2022-06-02 10:55:18 +00:00
## h3ExactEdgeLengthM
2022-01-13 03:32:19 +00:00
Returns the exact edge length of the unidirectional edge represented by the input h3 index in meters.
**Syntax**
``` sql
h3ExactEdgeLengthM(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-01-13 03:32:19 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Exact edge length in meters. [Float64 ](../../data-types/float.md ).
2022-01-13 03:32:19 +00:00
**Example**
Query:
``` sql
SELECT h3ExactEdgeLengthM(1310277011704381439) AS exactEdgeLengthM;;
```
Result:
``` text
┌───exactEdgeLengthM─┐
│ 195449.63163407316 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3ExactEdgeLengthKm
2022-01-14 07:41:32 +00:00
Returns the exact edge length of the unidirectional edge represented by the input h3 index in kilometers.
**Syntax**
``` sql
h3ExactEdgeLengthKm(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-01-14 07:41:32 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Exact edge length in kilometers. [Float64 ](../../data-types/float.md ).
2022-01-14 07:41:32 +00:00
**Example**
Query:
``` sql
SELECT h3ExactEdgeLengthKm(1310277011704381439) AS exactEdgeLengthKm;;
```
Result:
``` text
┌──exactEdgeLengthKm─┐
│ 195.44963163407317 │
└────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3ExactEdgeLengthRads
2022-01-14 07:50:16 +00:00
Returns the exact edge length of the unidirectional edge represented by the input h3 index in radians.
**Syntax**
``` sql
h3ExactEdgeLengthRads(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-01-14 07:50:16 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Exact edge length in radians. [Float64 ](../../data-types/float.md ).
2022-01-14 07:50:16 +00:00
**Example**
Query:
``` sql
SELECT h3ExactEdgeLengthRads(1310277011704381439) AS exactEdgeLengthRads;;
```
Result:
``` text
┌──exactEdgeLengthRads─┐
│ 0.030677980118976447 │
└──────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3NumHexagons
2022-01-14 08:26:06 +00:00
Returns the number of unique H3 indices at the given resolution.
**Syntax**
``` sql
h3NumHexagons(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2022-01-14 08:26:06 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Number of H3 indices. [Int64 ](../../data-types/int-uint.md ).
2022-01-14 08:26:06 +00:00
**Example**
Query:
``` sql
SELECT h3NumHexagons(3) AS numHexagons;
```
Result:
``` text
┌─numHexagons─┐
│ 41162 │
└─────────────┘
```
2022-05-01 17:47:56 +00:00
2023-01-04 19:53:02 +00:00
## h3PointDistM
Returns the "great circle" or "haversine" distance between pairs of GeoCoord points (latitude/longitude) pairs in meters.
**Syntax**
``` sql
h3PointDistM(lat1, lon1, lat2, lon2)
```
**Arguments**
2024-05-24 03:54:16 +00:00
- `lat1` , `lon1` — Latitude and Longitude of point1 in degrees. [Float64 ](../../data-types/float.md ).
- `lat2` , `lon2` — Latitude and Longitude of point2 in degrees. [Float64 ](../../data-types/float.md ).
2023-01-04 19:53:02 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Haversine or great circle distance in meters.[Float64](../../data-types/float.md).
2023-01-04 19:53:02 +00:00
**Example**
Query:
``` sql
select h3PointDistM(-10.0 ,0.0, 10.0, 0.0) as h3PointDistM;
```
Result:
``` text
┌──────h3PointDistM─┐
│ 2223901.039504589 │
└───────────────────┘
```
## h3PointDistKm
Returns the "great circle" or "haversine" distance between pairs of GeoCoord points (latitude/longitude) pairs in kilometers.
**Syntax**
``` sql
h3PointDistKm(lat1, lon1, lat2, lon2)
```
**Arguments**
2024-05-24 03:54:16 +00:00
- `lat1` , `lon1` — Latitude and Longitude of point1 in degrees. [Float64 ](../../data-types/float.md ).
- `lat2` , `lon2` — Latitude and Longitude of point2 in degrees. [Float64 ](../../data-types/float.md ).
2023-01-04 19:53:02 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Haversine or great circle distance in kilometers. [Float64 ](../../data-types/float.md ).
2023-01-04 19:53:02 +00:00
**Example**
Query:
``` sql
select h3PointDistKm(-10.0 ,0.0, 10.0, 0.0) as h3PointDistKm;
```
Result:
``` text
┌─────h3PointDistKm─┐
│ 2223.901039504589 │
└───────────────────┘
```
## h3PointDistRads
Returns the "great circle" or "haversine" distance between pairs of GeoCoord points (latitude/longitude) pairs in radians.
**Syntax**
``` sql
h3PointDistRads(lat1, lon1, lat2, lon2)
```
**Arguments**
2024-05-24 03:54:16 +00:00
- `lat1` , `lon1` — Latitude and Longitude of point1 in degrees. [Float64 ](../../data-types/float.md ).
- `lat2` , `lon2` — Latitude and Longitude of point2 in degrees. [Float64 ](../../data-types/float.md ).
2023-01-04 19:53:02 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Haversine or great circle distance in radians. [Float64 ](../../data-types/float.md ).
2023-01-04 19:53:02 +00:00
**Example**
Query:
``` sql
select h3PointDistRads(-10.0 ,0.0, 10.0, 0.0) as h3PointDistRads;
```
Result:
``` text
┌────h3PointDistRads─┐
│ 0.3490658503988659 │
└────────────────────┘
```
## h3GetRes0Indexes
Returns an array of all the resolution 0 H3 indexes.
**Syntax**
``` sql
h3GetRes0Indexes()
```
**Returned values**
2024-05-24 03:54:16 +00:00
- Array of all the resolution 0 H3 indexes. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2023-01-04 19:53:02 +00:00
**Example**
Query:
``` sql
select h3GetRes0Indexes as indexes ;
```
Result:
``` text
┌─indexes─────────────────────────────────────┐
│ [576495936675512319,576531121047601151,....]│
└─────────────────────────────────────────────┘
```
## h3GetPentagonIndexes
Returns all the pentagon H3 indexes at the specified resolution.
**Syntax**
``` sql
h3GetPentagonIndexes(resolution)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `resolution` — Index resolution. Range: `[0, 15]` . [UInt8 ](../../data-types/int-uint.md ).
2023-01-04 19:53:02 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Array of all pentagon H3 indexes. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2023-01-04 19:53:02 +00:00
**Example**
Query:
``` sql
SELECT h3GetPentagonIndexes(3) AS indexes;
```
Result:
``` text
┌─indexes────────────────────────────────────────────────────────┐
│ [590112357393367039,590464201114255359,590816044835143679,...] │
└────────────────────────────────────────────────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3Line
2022-05-08 05:42:57 +00:00
Returns the line of indices between the two indices that are provided.
**Syntax**
``` sql
h3Line(start,end)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `start` — Hexagon index number that represents a starting point. [UInt64 ](../../data-types/int-uint.md ).
- `end` — Hexagon index number that represents an ending point. [UInt64 ](../../data-types/int-uint.md ).
2022-05-08 05:42:57 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
Array of h3 indexes representing the line of indices between the two provided indices. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2022-05-08 05:42:57 +00:00
**Example**
Query:
``` sql
SELECT h3Line(590080540275638271,590103561300344831) as indexes;
```
Result:
``` text
┌─indexes────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [590080540275638271,590080471556161535,590080883873021951,590106516237844479,590104385934065663,590103630019821567,590103561300344831] │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
2022-06-02 10:55:18 +00:00
## h3Distance
2022-05-08 06:14:08 +00:00
Returns the distance in grid cells between the two indices that are provided.
**Syntax**
``` sql
h3Distance(start,end)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `start` — Hexagon index number that represents a starting point. [UInt64 ](../../data-types/int-uint.md ).
- `end` — Hexagon index number that represents an ending point. [UInt64 ](../../data-types/int-uint.md ).
2022-05-08 06:14:08 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Number of grid cells. [Int64 ](../../data-types/int-uint.md ).
2022-05-08 06:14:08 +00:00
Returns a negative number if finding the distance fails.
**Example**
Query:
``` sql
SELECT h3Distance(590080540275638271,590103561300344831) as distance;
```
Result:
``` text
┌─distance─┐
│ 7 │
└──────────┘
```
2022-06-02 10:55:18 +00:00
## h3HexRing
2022-05-09 05:03:46 +00:00
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
h3HexRing(index, k)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number that represents the origin. [UInt64 ](../../data-types/int-uint.md ).
- `k` — Distance. [UInt64 ](../../data-types/int-uint.md ).
2022-05-09 05:03:46 +00:00
**Returned values**
2024-05-24 03:54:16 +00:00
- Array of H3 indexes. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2022-05-09 05:03:46 +00:00
**Example**
Query:
``` sql
SELECT h3HexRing(590080540275638271, toUInt16(1)) AS hexRing;
```
Result:
``` text
┌─hexRing─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [590080815153545215,590080471556161535,590080677714591743,590077585338138623,590077447899185151,590079509483487231] │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
2022-05-18 03:10:03 +00:00
2022-06-02 10:55:18 +00:00
## h3GetUnidirectionalEdge
2022-05-01 17:47:56 +00:00
Returns a unidirectional edge H3 index based on the provided origin and destination and returns 0 on error.
**Syntax**
``` sql
h3GetUnidirectionalEdge(originIndex, destinationIndex)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `originIndex` — Origin Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `destinationIndex` — Destination Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 17:47:56 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Unidirectional Edge Hexagon Index number. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 17:47:56 +00:00
**Example**
Query:
``` sql
SELECT h3GetUnidirectionalEdge(599686042433355775, 599686043507097599) as edge;
```
Result:
``` text
┌────────────────edge─┐
│ 1248204388774707199 │
└─────────────────────┘
```
2022-05-01 20:27:48 +00:00
2022-06-02 10:55:18 +00:00
## h3UnidirectionalEdgeIsValid
2022-05-01 20:27:48 +00:00
Determines if the provided H3Index is a valid unidirectional edge index. Returns 1 if it's a unidirectional edge and 0 otherwise.
**Syntax**
``` sql
h3UnidirectionalEdgeisValid(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 20:27:48 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- 1 — The H3 index is a valid unidirectional edge. [UInt8 ](../../data-types/int-uint.md ).
- 0 — The H3 index is not a valid unidirectional edge. [UInt8 ](../../data-types/int-uint.md ).
2022-05-01 20:27:48 +00:00
**Example**
Query:
``` sql
SELECT h3UnidirectionalEdgeIsValid(1248204388774707199) as validOrNot;
```
Result:
``` text
┌─validOrNot─┐
│ 1 │
└────────────┘
```
2022-05-01 20:53:44 +00:00
2022-06-02 10:55:18 +00:00
## h3GetOriginIndexFromUnidirectionalEdge
2022-05-01 20:53:44 +00:00
Returns the origin hexagon index from the unidirectional edge H3Index.
**Syntax**
``` sql
h3GetOriginIndexFromUnidirectionalEdge(edge)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `edge` — Hexagon index number that represents a unidirectional edge. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 20:53:44 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Origin Hexagon Index number. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 20:53:44 +00:00
**Example**
Query:
``` sql
SELECT h3GetOriginIndexFromUnidirectionalEdge(1248204388774707197) as origin;
```
Result:
``` text
┌─────────────origin─┐
│ 599686042433355773 │
└────────────────────┘
```
2022-05-01 21:11:53 +00:00
2022-06-02 10:55:18 +00:00
## h3GetDestinationIndexFromUnidirectionalEdge
2022-05-01 21:11:53 +00:00
Returns the destination hexagon index from the unidirectional edge H3Index.
**Syntax**
``` sql
h3GetDestinationIndexFromUnidirectionalEdge(edge)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `edge` — Hexagon index number that represents a unidirectional edge. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 21:11:53 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Destination Hexagon Index number. [UInt64 ](../../data-types/int-uint.md ).
2022-05-01 21:11:53 +00:00
**Example**
Query:
``` sql
SELECT h3GetDestinationIndexFromUnidirectionalEdge(1248204388774707197) as destination;
```
Result:
``` text
┌────────destination─┐
│ 599686043507097597 │
└────────────────────┘
```
2022-05-02 04:34:32 +00:00
2022-06-02 10:55:18 +00:00
## h3GetIndexesFromUnidirectionalEdge
2022-05-02 04:34:32 +00:00
Returns the origin and destination hexagon indexes from the given unidirectional edge H3Index.
**Syntax**
``` sql
h3GetIndexesFromUnidirectionalEdge(edge)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `edge` — Hexagon index number that represents a unidirectional edge. [UInt64 ](../../data-types/int-uint.md ).
2022-05-02 04:34:32 +00:00
**Returned value**
A tuple consisting of two values `tuple(origin,destination)` :
2024-05-24 03:54:16 +00:00
- `origin` — Origin Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
- `destination` — Destination Hexagon index number. [UInt64 ](../../data-types/int-uint.md ).
2022-05-02 04:34:32 +00:00
Returns `(0,0)` if the provided input is not valid.
**Example**
Query:
``` sql
SELECT h3GetIndexesFromUnidirectionalEdge(1248204388774707199) as indexes;
```
Result:
``` text
┌─indexes─────────────────────────────────┐
│ (599686042433355775,599686043507097599) │
└─────────────────────────────────────────┘
```
2022-05-02 05:38:01 +00:00
2022-06-02 10:55:18 +00:00
## h3GetUnidirectionalEdgesFromHexagon
2022-05-02 05:38:01 +00:00
Provides all of the unidirectional edges from the provided H3Index.
**Syntax**
``` sql
h3GetUnidirectionalEdgesFromHexagon(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number that represents a unidirectional edge. [UInt64 ](../../data-types/int-uint.md ).
2022-05-02 05:38:01 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
Array of h3 indexes representing each unidirectional edge. [Array ](../../data-types/array.md )([UInt64](../../data-types/int-uint.md)).
2022-05-02 05:38:01 +00:00
**Example**
Query:
``` sql
SELECT h3GetUnidirectionalEdgesFromHexagon(1248204388774707199) as edges;
```
Result:
``` text
┌─edges─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [1248204388774707199,1320261982812635135,1392319576850563071,1464377170888491007,1536434764926418943,1608492358964346879] │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
2022-05-03 04:53:39 +00:00
2022-06-02 10:55:18 +00:00
## h3GetUnidirectionalEdgeBoundary
2022-05-03 04:53:39 +00:00
Returns the coordinates defining the unidirectional edge.
**Syntax**
``` sql
h3GetUnidirectionalEdgeBoundary(index)
```
**Parameter**
2024-05-24 03:54:16 +00:00
- `index` — Hexagon index number that represents a unidirectional edge. [UInt64 ](../../data-types/int-uint.md ).
2022-05-03 04:53:39 +00:00
**Returned value**
2024-05-24 03:54:16 +00:00
- Array of pairs '(lon, lat)'. [Array ](../../data-types/array.md )([Float64](../../data-types/float.md), [Float64 ](../../data-types/float.md )).
2022-05-03 04:53:39 +00:00
**Example**
Query:
``` sql
SELECT h3GetUnidirectionalEdgeBoundary(1248204388774707199) as boundary;
```
Result:
``` text
┌─boundary────────────────────────────────────────────────────────────────────────┐
│ [(37.42012867767779,-122.03773496427027),(37.33755608435299,-122.090428929044)] │
└─────────────────────────────────────────────────────────────────────────────────┘
```