跳到主要内容

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

FunctionDescriptionExample
GEO_TO_H3Converts longitude/latitude to H3 indexGEO_TO_H3(37.7950, 55.7129, 15)644325524701193974
H3_TO_GEOConverts H3 index to longitude/latitudeH3_TO_GEO(644325524701193974)[37.7950, 55.7129]
H3_TO_STRINGConverts H3 index to string representationH3_TO_STRING(644325524701193974)'8f2830828052d25'
STRING_TO_H3Converts string representation to H3 indexSTRING_TO_H3('8f2830828052d25')644325524701193974
GEOHASH_ENCODEEncodes longitude/latitude to geohash stringGEOHASH_ENCODE(37.7950, 55.7129, 12)'ucfv0nzpt3s7'
GEOHASH_DECODEDecodes geohash string to longitude/latitudeGEOHASH_DECODE('ucfv0nzpt3s7')[37.7950, 55.7129]

Hexagon Properties

FunctionDescriptionExample
H3_GET_RESOLUTIONReturns the resolution of an H3 indexH3_GET_RESOLUTION(644325524701193974)15
H3_GET_BASE_CELLReturns the base cell number of an H3 indexH3_GET_BASE_CELL(644325524701193974)14
H3_IS_VALIDChecks if an H3 index is validH3_IS_VALID(644325524701193974)TRUE
H3_IS_PENTAGONChecks if an H3 index is a pentagonH3_IS_PENTAGON(644325524701193974)FALSE
H3_IS_RES_CLASS_IIIChecks if an H3 index is in resolution class IIIH3_IS_RES_CLASS_III(644325524701193974)FALSE
H3_GET_FACESReturns the icosahedron faces intersected by an H3 cellH3_GET_FACES(644325524701193974)[7]
H3_TO_PARENTReturns the parent of an H3 index at a specified resolutionH3_TO_PARENT(644325524701193974, 10)622236721289822207
H3_TO_CHILDRENReturns the children of an H3 index at a specified resolutionH3_TO_CHILDREN(622236721289822207, 11)[...]
H3_TO_CENTER_CHILDReturns the center child of an H3 index at a specified resolutionH3_TO_CENTER_CHILD(622236721289822207, 11)625561602857582591

Area and Boundary

FunctionDescriptionExample
H3_CELL_AREA_M2Returns the area of an H3 cell in square metersH3_CELL_AREA_M2(644325524701193974)0.8953
H3_CELL_AREA_RADS2Returns the area of an H3 cell in square radiansH3_CELL_AREA_RADS2(644325524701193974)2.2e-14
H3_HEX_AREA_KM2Returns the average hexagon area in square kilometers at a resolutionH3_HEX_AREA_KM2(10)0.0152
H3_HEX_AREA_M2Returns the average hexagon area in square meters at a resolutionH3_HEX_AREA_M2(10)15200
H3_TO_GEO_BOUNDARYReturns the boundary of an H3 cell as an array of coordinatesH3_TO_GEO_BOUNDARY(644325524701193974)[[lon1,lat1], [lon2,lat2], ...]
H3_NUM_HEXAGONSReturns the number of hexagons at a resolutionH3_NUM_HEXAGONS(2)5882

Hexagon Relationships

FunctionDescriptionExample
H3_DISTANCEReturns the grid distance between two H3 indexesH3_DISTANCE(599119489002373119, 599119491149856767)1
H3_INDEXES_ARE_NEIGHBORSChecks if two H3 indexes are neighborsH3_INDEXES_ARE_NEIGHBORS(599119489002373119, 599119491149856767)TRUE
H3_K_RINGReturns all H3 indexes within k distance of the originH3_K_RING(599119489002373119, 1)[599119489002373119, 599119491149856767, ...]
H3_HEX_RINGReturns all H3 indexes at exactly k distance from the originH3_HEX_RING(599119489002373119, 1)[599119491149856767, ...]

Edge Functions

FunctionDescriptionExample
H3_GET_UNIDIRECTIONAL_EDGEReturns the edge index between two adjacent H3 indexesH3_GET_UNIDIRECTIONAL_EDGE(from_h3, to_h3)edge_index
H3_UNIDIRECTIONAL_EDGE_IS_VALIDChecks if an H3 edge index is validH3_UNIDIRECTIONAL_EDGE_IS_VALID(edge_index)TRUE
H3_GET_ORIGIN_INDEX_FROM_UNIDIRECTIONAL_EDGEReturns the origin H3 index from an edgeH3_GET_ORIGIN_INDEX_FROM_UNIDIRECTIONAL_EDGE(edge_index)from_h3
H3_GET_DESTINATION_INDEX_FROM_UNIDIRECTIONAL_EDGEReturns the destination H3 index from an edgeH3_GET_DESTINATION_INDEX_FROM_UNIDIRECTIONAL_EDGE(edge_index)to_h3
H3_GET_INDEXES_FROM_UNIDIRECTIONAL_EDGEReturns both origin and destination H3 indexes from an edgeH3_GET_INDEXES_FROM_UNIDIRECTIONAL_EDGE(edge_index)[from_h3, to_h3]
H3_GET_UNIDIRECTIONAL_EDGES_FROM_HEXAGONReturns all edges originating from an H3 indexH3_GET_UNIDIRECTIONAL_EDGES_FROM_HEXAGON(h3_index)[edge1, edge2, ...]
H3_GET_UNIDIRECTIONAL_EDGE_BOUNDARYReturns the boundary of an H3 edgeH3_GET_UNIDIRECTIONAL_EDGE_BOUNDARY(edge_index)[[lon1,lat1], [lon2,lat2]]

Measurement

FunctionDescriptionExample
H3_EDGE_LENGTH_KMReturns the average edge length in kilometers at a resolutionH3_EDGE_LENGTH_KM(10)0.065
H3_EDGE_LENGTH_MReturns the average edge length in meters at a resolutionH3_EDGE_LENGTH_M(10)65.91
H3_EXACT_EDGE_LENGTH_KMReturns the exact edge length in kilometersH3_EXACT_EDGE_LENGTH_KM(edge_index)0.066
H3_EXACT_EDGE_LENGTH_MReturns the exact edge length in metersH3_EXACT_EDGE_LENGTH_M(edge_index)66.12
H3_EXACT_EDGE_LENGTH_RADSReturns the exact edge length in radiansH3_EXACT_EDGE_LENGTH_RADS(edge_index)0.00001
H3_EDGE_ANGLEReturns the angle in radians between two edgesH3_EDGE_ANGLE(edge1, edge2)1.047

General Utility

FunctionDescriptionExample
POINT_IN_POLYGONChecks if a point is inside a polygonPOINT_IN_POLYGON([lon, lat], [[p1_lon, p1_lat], [p2_lon, p2_lat], ...])TRUE
H3_LINEReturns H3 indexes in a line between two H3 indexesH3_LINE(from_h3, to_h3)[from_h3, ..., to_h3]