Skip to main content
Skip to main content

Functions for Working with H3 Indexes

H3 Index

H3 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.

h3IsValid

Verifies whether the number is a valid H3 index.

Syntax

Parameter

  • h3index — Hexagon index number. UInt64.

Returned values

  • 1 — The number is a valid H3 index. UInt8.
  • 0 — The number is not a valid H3 index. UInt8.

Example

Query:

Result:

h3GetResolution

Defines the resolution of the given H3 index.

Syntax

Parameter

  • h3index — Hexagon index number. UInt64.

Returned values

  • Index resolution. Range: [0, 15]. UInt8.
  • If the index is not valid, the function returns a random value. Use h3IsValid to verify the index. UInt8.

Example

Query:

Result:

h3EdgeAngle

Calculates the average length of an H3 hexagon edge in grades.

Syntax

Parameter

  • resolution — Index resolution. UInt8. Range: [0, 15].

Returned values

  • The average length of an H3 hexagon edge in grades. Float64.

Example

Query:

Result:

h3EdgeLengthM

Calculates the average length of an H3 hexagon edge in meters.

Syntax

Parameter

  • resolution — Index resolution. UInt8. Range: [0, 15].

Returned values

  • The average edge length of an H3 hexagon in meters. Float64.

Example

Query:

Result:

h3EdgeLengthKm

Calculates the average length of an H3 hexagon edge in kilometers.

Syntax

Parameter

  • resolution — Index resolution. UInt8. Range: [0, 15].

Returned values

  • The average length of an H3 hexagon edge in kilometers. Float64.

Example

Query:

Result:

geoToH3

Returns H3 point index (lon, lat) with specified resolution.

Syntax

Arguments

  • lon — Longitude. Float64.
  • lat — Latitude. Float64.
  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned values

Example

Query:

Result:

h3ToGeo

Returns the centroid longitude and latitude corresponding to the provided H3 index.

Syntax

Arguments

  • h3Index — H3 Index. UInt64.

Returned values

  • A tuple consisting of two values: tuple(lat,lon). lat — Latitude. Float64. lon — Longitude. Float64.

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

Query:

Result:

h3ToGeoBoundary

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

Syntax

Arguments

  • h3Index — H3 Index. UInt64.

Returned values

Example

Query:

Result:

h3kRing

Lists all the H3 hexagons in the raduis of k from the given hexagon in random order.

Syntax

Arguments

  • h3index — Hexagon index number. UInt64.
  • k — Radius. integer

Returned values

Example

Query:

Result:

h3GetBaseCell

Returns the base cell number of the H3 index.

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Hexagon base cell number. UInt8.

Example

Query:

Result:

h3HexAreaM2

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

Syntax

Parameter

  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned value

Example

Query:

Result:

h3HexAreaKm2

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

Syntax

Parameter

  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned value

  • Area in square kilometers. Float64.

Example

Query:

Result:

h3IndexesAreNeighbors

Returns whether or not the provided H3 indexes are neighbors.

Syntax

Arguments

  • index1 — Hexagon index number. UInt64.
  • index2 — Hexagon index number. UInt64.

Returned value

  • 1 — Indexes are neighbours. UInt8.
  • 0 — Indexes are not neighbours. UInt8.

Example

Query:

Result:

h3ToChildren

Returns an array of child indexes for the given H3 index.

Syntax

Arguments

  • index — Hexagon index number. UInt64.
  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned values

Example

Query:

Result:

h3ToParent

Returns the parent (coarser) index containing the given H3 index.

Syntax

Arguments

  • index — Hexagon index number. UInt64.
  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned value

Example

Query:

Result:

h3ToString

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

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • String representation of the H3 index. String.

Example

Query:

Result:

stringToH3

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

Syntax

Parameter

  • index_str — String representation of the H3 index. String.

Returned value

  • Hexagon index number. Returns 0 on error. UInt64.

Example

Query:

Result:

h3GetResolution

Returns the resolution of the H3 index.

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Index resolution. Range: [0, 15]. UInt8.

Example

Query:

Result:

h3IsResClassIII

Returns whether H3 index has a resolution with Class III orientation.

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • 1 — Index has a resolution with Class III orientation. UInt8.
  • 0 — Index doesn't have a resolution with Class III orientation. UInt8.

Example

Query:

Result:

h3IsPentagon

Returns whether this H3 index represents a pentagonal cell.

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • 1 — Index represents a pentagonal cell. UInt8.
  • 0 — Index doesn't represent a pentagonal cell. UInt8.

Example

Query:

Result:

h3GetFaces

Returns icosahedron faces intersected by a given H3 index.

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned values

  • Array containing icosahedron faces intersected by a given H3 index. Array(UInt64).

Example

Query:

Result:

h3CellAreaM2

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

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Cell area in square meters. Float64.

Example

Query:

Result:

h3CellAreaRads2

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

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Cell area in square radians. Float64.

Example

Query:

Result:

h3ToCenterChild

Returns the center child (finer) H3 index contained by given H3 at the given resolution.

Syntax

Parameter

  • index — Hexagon index number. UInt64.
  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned values

  • H3 index of the center child contained by given H3 at the given resolution. UInt64.

Example

Query:

Result:

h3ExactEdgeLengthM

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

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Exact edge length in meters. Float64.

Example

Query:

Result:

h3ExactEdgeLengthKm

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

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Exact edge length in kilometers. Float64.

Example

Query:

Result:

h3ExactEdgeLengthRads

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

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • Exact edge length in radians. Float64.

Example

Query:

Result:

h3NumHexagons

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

Syntax

Parameter

  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned value

  • Number of H3 indices. Int64.

Example

Query:

Result:

h3PointDistM

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

Syntax

Arguments

  • lat1, lon1 — Latitude and Longitude of point1 in degrees. Float64.
  • lat2, lon2 — Latitude and Longitude of point2 in degrees. Float64.

Returned values

  • Haversine or great circle distance in meters.Float64.

Example

Query:

Result:

h3PointDistKm

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

Syntax

Arguments

  • lat1, lon1 — Latitude and Longitude of point1 in degrees. Float64.
  • lat2, lon2 — Latitude and Longitude of point2 in degrees. Float64.

Returned values

  • Haversine or great circle distance in kilometers. Float64.

Example

Query:

Result:

h3PointDistRads

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

Syntax

Arguments

  • lat1, lon1 — Latitude and Longitude of point1 in degrees. Float64.
  • lat2, lon2 — Latitude and Longitude of point2 in degrees. Float64.

Returned values

  • Haversine or great circle distance in radians. Float64.

Example

Query:

Result:

h3GetRes0Indexes

Returns an array of all the resolution 0 H3 indexes.

Syntax

Returned values

  • Array of all the resolution 0 H3 indexes. Array(UInt64).

Example

Query:

Result:

h3GetPentagonIndexes

Returns all the pentagon H3 indexes at the specified resolution.

Syntax

Parameter

  • resolution — Index resolution. Range: [0, 15]. UInt8.

Returned value

Example

Query:

Result:

h3Line

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

Syntax

Parameter

  • start — Hexagon index number that represents a starting point. UInt64.
  • end — Hexagon index number that represents an ending point. UInt64.

Returned value

Array of h3 indexes representing the line of indices between the two provided indices. Array(UInt64).

Example

Query:

Result:

h3Distance

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

Syntax

Parameter

  • start — Hexagon index number that represents a starting point. UInt64.
  • end — Hexagon index number that represents an ending point. UInt64.

Returned value

  • Number of grid cells. Int64.

Returns a negative number if finding the distance fails.

Example

Query:

Result:

h3HexRing

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

Parameter

  • index — Hexagon index number that represents the origin. UInt64.
  • k — Distance. UInt64.

Returned values

Example

Query:

Result:

h3GetUnidirectionalEdge

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

Syntax

Parameter

  • originIndex — Origin Hexagon index number. UInt64.
  • destinationIndex — Destination Hexagon index number. UInt64.

Returned value

  • Unidirectional Edge Hexagon Index number. UInt64.

Example

Query:

Result:

h3UnidirectionalEdgeIsValid

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

Syntax

Parameter

  • index — Hexagon index number. UInt64.

Returned value

  • 1 — The H3 index is a valid unidirectional edge. UInt8.
  • 0 — The H3 index is not a valid unidirectional edge. UInt8.

Example

Query:

Result:

h3GetOriginIndexFromUnidirectionalEdge

Returns the origin hexagon index from the unidirectional edge H3Index.

Syntax

Parameter

  • edge — Hexagon index number that represents a unidirectional edge. UInt64.

Returned value

  • Origin Hexagon Index number. UInt64.

Example

Query:

Result:

h3GetDestinationIndexFromUnidirectionalEdge

Returns the destination hexagon index from the unidirectional edge H3Index.

Syntax

Parameter

  • edge — Hexagon index number that represents a unidirectional edge. UInt64.

Returned value

  • Destination Hexagon Index number. UInt64.

Example

Query:

Result:

h3GetIndexesFromUnidirectionalEdge

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

Syntax

Parameter

  • edge — Hexagon index number that represents a unidirectional edge. UInt64.

Returned value

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

  • origin — Origin Hexagon index number. UInt64.
  • destination — Destination Hexagon index number. UInt64.

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

Example

Query:

Result:

h3GetUnidirectionalEdgesFromHexagon

Provides all of the unidirectional edges from the provided H3Index.

Syntax

Parameter

  • index — Hexagon index number that represents a unidirectional edge. UInt64.

Returned value

Array of h3 indexes representing each unidirectional edge. Array(UInt64).

Example

Query:

Result:

h3GetUnidirectionalEdgeBoundary

Returns the coordinates defining the unidirectional edge.

Syntax

Parameter

  • index — Hexagon index number that represents a unidirectional edge. UInt64.

Returned value

Example

Query:

Result: