H3 Functions
This section provides reference information for the H3 functions in Databend. H3 is a geospatial indexing system that partitions the world into hexagonal cells, enabling efficient spatial analysis and operations.
Coordinate Conversion
Function | Description | Example |
---|---|---|
GEO_TO_H3 | Converts longitude/latitude to H3 index | GEO_TO_H3(37.7950, 55.7129, 15) → 644325524701193974 |
H3_TO_GEO | Converts H3 index to longitude/latitude | H3_TO_GEO(644325524701193974) → [37.7950, 55.7129] |
H3_TO_STRING | Converts H3 index to string representation | H3_TO_STRING(644325524701193974) → '8f2830828052d25' |
STRING_TO_H3 | Converts string representation to H3 index | STRING_TO_H3('8f2830828052d25') → 644325524701193974 |
GEOHASH_ENCODE | Encodes longitude/latitude to geohash string | GEOHASH_ENCODE(37.7950, 55.7129, 12) → 'ucfv0nzpt3s7' |
GEOHASH_DECODE | Decodes geohash string to longitude/latitude | GEOHASH_DECODE('ucfv0nzpt3s7') → [37.7950, 55.7129] |
Hexagon Properties
Function | Description | Example |
---|---|---|
H3_GET_RESOLUTION | Returns the resolution of an H3 index | H3_GET_RESOLUTION(644325524701193974) → 15 |
H3_GET_BASE_CELL | Returns the base cell number of an H3 index | H3_GET_BASE_CELL(644325524701193974) → 14 |
H3_IS_VALID | Checks if an H3 index is valid | H3_IS_VALID(644325524701193974) → TRUE |
H3_IS_PENTAGON | Checks if an H3 index is a pentagon | H3_IS_PENTAGON(644325524701193974) → FALSE |
H3_IS_RES_CLASS_III | Checks if an H3 index is in resolution class III | H3_IS_RES_CLASS_III(644325524701193974) → FALSE |
H3_GET_FACES | Returns the icosahedron faces intersected by an H3 cell | H3_GET_FACES(644325524701193974) → [7] |
H3_TO_PARENT | Returns the parent of an H3 index at a specified resolution | H3_TO_PARENT(644325524701193974, 10) → 622236721289822207 |
H3_TO_CHILDREN | Returns the children of an H3 index at a specified resolution | H3_TO_CHILDREN(622236721289822207, 11) → [...] |
H3_TO_CENTER_CHILD | Returns the center child of an H3 index at a specified resolution | H3_TO_CENTER_CHILD(622236721289822207, 11) → 625561602857582591 |
Area and Boundary
Function | Description | Example |
---|---|---|
H3_CELL_AREA_M2 | Returns the area of an H3 cell in square meters | H3_CELL_AREA_M2(644325524701193974) → 0.8953 |
H3_CELL_AREA_RADS2 | Returns the area of an H3 cell in square radians | H3_CELL_AREA_RADS2(644325524701193974) → 2.2e-14 |
H3_HEX_AREA_KM2 | Returns the average hexagon area in square kilometers at a resolution | H3_HEX_AREA_KM2(10) → 0.0152 |
H3_HEX_AREA_M2 | Returns the average hexagon area in square meters at a resolution | H3_HEX_AREA_M2(10) → 15200 |
H3_TO_GEO_BOUNDARY | Returns the boundary of an H3 cell as an array of coordinates | H3_TO_GEO_BOUNDARY(644325524701193974) → [[lon1,lat1], [lon2,lat2], ...] |
H3_NUM_HEXAGONS | Returns the number of hexagons at a resolution | H3_NUM_HEXAGONS(2) → 5882 |
Hexagon Relationships
Function | Description | Example |
---|---|---|
H3_DISTANCE | Returns the grid distance between two H3 indexes | H3_DISTANCE(599119489002373119, 599119491149856767) → 1 |
H3_INDEXES_ARE_NEIGHBORS | Checks if two H3 indexes are neighbors | H3_INDEXES_ARE_NEIGHBORS(599119489002373119, 599119491149856767) → TRUE |
H3_K_RING | Returns all H3 indexes within k distance of the origin | H3_K_RING(599119489002373119, 1) → [599119489002373119, 599119491149856767, ...] |
H3_HEX_RING | Returns all H3 indexes at exactly k distance from the origin | H3_HEX_RING(599119489002373119, 1) → [599119491149856767, ...] |
Edge Functions
Function | Description | Example |
---|---|---|
H3_GET_UNIDIRECTIONAL_EDGE | Returns the edge index between two adjacent H3 indexes | H3_GET_UNIDIRECTIONAL_EDGE(from_h3, to_h3) → edge_index |
H3_UNIDIRECTIONAL_EDGE_IS_VALID | Checks if an H3 edge index is valid | H3_UNIDIRECTIONAL_EDGE_IS_VALID(edge_index) → TRUE |
H3_GET_ORIGIN_INDEX_FROM_UNIDIRECTIONAL_EDGE | Returns the origin H3 index from an edge | H3_GET_ORIGIN_INDEX_FROM_UNIDIRECTIONAL_EDGE(edge_index) → from_h3 |
H3_GET_DESTINATION_INDEX_FROM_UNIDIRECTIONAL_EDGE | Returns the destination H3 index from an edge | H3_GET_DESTINATION_INDEX_FROM_UNIDIRECTIONAL_EDGE(edge_index) → to_h3 |
H3_GET_INDEXES_FROM_UNIDIRECTIONAL_EDGE | Returns both origin and destination H3 indexes from an edge | H3_GET_INDEXES_FROM_UNIDIRECTIONAL_EDGE(edge_index) → [from_h3, to_h3] |
H3_GET_UNIDIRECTIONAL_EDGES_FROM_HEXAGON | Returns all edges originating from an H3 index | H3_GET_UNIDIRECTIONAL_EDGES_FROM_HEXAGON(h3_index) → [edge1, edge2, ...] |
H3_GET_UNIDIRECTIONAL_EDGE_BOUNDARY | Returns the boundary of an H3 edge | H3_GET_UNIDIRECTIONAL_EDGE_BOUNDARY(edge_index) → [[lon1,lat1], [lon2,lat2]] |
Measurement
Function | Description | Example |
---|---|---|
H3_EDGE_LENGTH_KM | Returns the average edge length in kilometers at a resolution | H3_EDGE_LENGTH_KM(10) → 0.065 |
H3_EDGE_LENGTH_M | Returns the average edge length in meters at a resolution | H3_EDGE_LENGTH_M(10) → 65.91 |
H3_EXACT_EDGE_LENGTH_KM | Returns the exact edge length in kilometers | H3_EXACT_EDGE_LENGTH_KM(edge_index) → 0.066 |
H3_EXACT_EDGE_LENGTH_M | Returns the exact edge length in meters | H3_EXACT_EDGE_LENGTH_M(edge_index) → 66.12 |
H3_EXACT_EDGE_LENGTH_RADS | Returns the exact edge length in radians | H3_EXACT_EDGE_LENGTH_RADS(edge_index) → 0.00001 |
H3_EDGE_ANGLE | Returns the angle in radians between two edges | H3_EDGE_ANGLE(edge1, edge2) → 1.047 |
General Utility
Function | Description | Example |
---|---|---|
POINT_IN_POLYGON | Checks if a point is inside a polygon | POINT_IN_POLYGON([lon, lat], [[p1_lon, p1_lat], [p2_lon, p2_lat], ...]) → TRUE |
H3_LINE | Returns H3 indexes in a line between two H3 indexes | H3_LINE(from_h3, to_h3) → [from_h3, ..., to_h3] |