Skip to main content

Geospatial Functions

Databend ships with two complementary sets of geospatial capabilities: PostGIS-style geometry functions for building and analysing shapes, and H3 utilities for global hexagonal indexing. The tables below group the functions by task so you can quickly locate the right tool, similar to the layout used in the Snowflake documentation.

Geometry Constructors

FunctionDescriptionExample
ST_MAKEGEOMPOINT / ST_GEOM_POINTConstruct a Point geometryST_MAKEGEOMPOINT(-122.35, 37.55)POINT(-122.35 37.55)
ST_MAKELINE / ST_MAKE_LINECreate a LineString from pointsST_MAKELINE(ST_MAKEGEOMPOINT(-122.35, 37.55), ST_MAKEGEOMPOINT(-122.40, 37.60))LINESTRING(-122.35 37.55, -122.40 37.60)
ST_MAKEPOLYGONCreate a Polygon from a closed LineStringST_MAKEPOLYGON(ST_MAKELINE(...))POLYGON(...)
ST_POLYGONCreate a Polygon from coordinate ringsST_POLYGON(...)POLYGON(...)

Geometry Conversion

FunctionDescriptionExample
ST_GEOMETRYFROMTEXT / ST_GEOMFROMTEXTConvert WKT to geometryST_GEOMETRYFROMTEXT('POINT(-122.35 37.55)')POINT(-122.35 37.55)
ST_GEOMETRYFROMWKB / ST_GEOMFROMWKBConvert WKB to geometryST_GEOMETRYFROMWKB(...)POINT(...)
ST_GEOMETRYFROMEWKT / ST_GEOMFROMEWKTConvert EWKT to geometryST_GEOMETRYFROMEWKT('SRID=4326;POINT(-122.35 37.55)')POINT(-122.35 37.55)
ST_GEOMETRYFROMEWKB / ST_GEOMFROMEWKBConvert EWKB to geometryST_GEOMETRYFROMEWKB(...)POINT(...)
ST_GEOMFROMGEOHASHConvert GeoHash to geometryST_GEOMFROMGEOHASH('9q8yyk8')POLYGON(...)
ST_GEOMPOINTFROMGEOHASHConvert GeoHash to Point geometryST_GEOMPOINTFROMGEOHASH('9q8yyk8')POINT(...)
TO_GEOMETRYParse various formats into geometryTO_GEOMETRY('POINT(-122.35 37.55)')POINT(-122.35 37.55)

Geometry Output

FunctionDescriptionExample
ST_ASTEXTConvert geometry to WKTST_ASTEXT(ST_MAKEGEOMPOINT(-122.35, 37.55))'POINT(-122.35 37.55)'
ST_ASWKTConvert geometry to WKTST_ASWKT(ST_MAKEGEOMPOINT(-122.35, 37.55))'POINT(-122.35 37.55)'
ST_ASBINARY / ST_ASWKBConvert geometry to WKBST_ASBINARY(ST_MAKEGEOMPOINT(-122.35, 37.55))WKB representation
ST_ASEWKTConvert geometry to EWKTST_ASEWKT(ST_MAKEGEOMPOINT(-122.35, 37.55))'SRID=4326;POINT(-122.35 37.55)'
ST_ASEWKBConvert geometry to EWKBST_ASEWKB(ST_MAKEGEOMPOINT(-122.35, 37.55))EWKB representation
ST_ASGEOJSONConvert geometry to GeoJSONST_ASGEOJSON(ST_MAKEGEOMPOINT(-122.35, 37.55))'{"type":"Point","coordinates":[-122.35,37.55]}'
ST_GEOHASHConvert geometry to GeoHashST_GEOHASH(ST_MAKEGEOMPOINT(-122.35, 37.55), 7)'9q8yyk8'
TO_STRINGConvert geometry to stringTO_STRING(ST_MAKEGEOMPOINT(-122.35, 37.55))'POINT(-122.35 37.55)'

Geometry Accessors & Properties

FunctionDescriptionExample
ST_DIMENSIONReturn the topological dimensionST_DIMENSION(ST_MAKEGEOMPOINT(-122.35, 37.55))0
ST_SRIDReturn the SRID of a geometryST_SRID(ST_MAKEGEOMPOINT(-122.35, 37.55))4326
ST_SETSRIDAssign an SRID to a geometryST_SETSRID(ST_MAKEGEOMPOINT(-122.35, 37.55), 3857)POINT(-122.35 37.55)
ST_TRANSFORMTransform geometry to a new SRIDST_TRANSFORM(ST_MAKEGEOMPOINT(-122.35, 37.55), 3857)POINT(-13618288.8 4552395.0)
ST_NPOINTS / ST_NUMPOINTSCount points in a geometryST_NPOINTS(ST_MAKELINE(...))2
ST_POINTNReturn a specific point from a LineStringST_POINTN(ST_MAKELINE(...), 1)POINT(-122.35 37.55)
ST_STARTPOINTReturn the first point in a LineStringST_STARTPOINT(ST_MAKELINE(...))POINT(-122.35 37.55)
ST_ENDPOINTReturn the last point in a LineStringST_ENDPOINT(ST_MAKELINE(...))POINT(-122.40 37.60)
ST_LENGTHMeasure the length of a LineStringST_LENGTH(ST_MAKELINE(...))5.57
ST_X / ST_YReturn the X or Y coordinate of a PointST_X(ST_MAKEGEOMPOINT(-122.35, 37.55))-122.35
ST_XMIN / ST_XMAXReturn the min/max X coordinateST_XMIN(ST_MAKELINE(...))-122.40
ST_YMIN / ST_YMAXReturn the min/max Y coordinateST_YMAX(ST_MAKELINE(...))37.60

Spatial Relationships

FunctionDescriptionExample
ST_CONTAINSTest whether one geometry contains anotherST_CONTAINS(ST_MAKEPOLYGON(...), ST_MAKEGEOMPOINT(...))TRUE
POINT_IN_POLYGONCheck if a point lies inside a polygonPOINT_IN_POLYGON([lon, lat], [[p1_lon, p1_lat], ...])TRUE

Distance & Measurements

FunctionDescriptionExample
ST_DISTANCEMeasure the distance between geometriesST_DISTANCE(ST_MAKEGEOMPOINT(-122.35, 37.55), ST_MAKEGEOMPOINT(-122.40, 37.60))5.57
HAVERSINECompute great-circle distance between coordinatesHAVERSINE(37.55, -122.35, 37.60, -122.40)6.12

H3 Indexing & Conversion

FunctionDescriptionExample
GEO_TO_H3Convert longitude/latitude to an H3 indexGEO_TO_H3(37.7950, 55.7129, 15)644325524701193974
H3_TO_GEOConvert an H3 index to longitude/latitudeH3_TO_GEO(644325524701193974)[37.7950, 55.7129]
H3_TO_STRINGConvert an H3 index to its string formH3_TO_STRING(644325524701193974)'8f2830828052d25'
STRING_TO_H3Convert an H3 string to an indexSTRING_TO_H3('8f2830828052d25')644325524701193974
GEOHASH_ENCODEEncode longitude/latitude to GeoHashGEOHASH_ENCODE(37.7950, 55.7129, 12)'ucfv0nzpt3s7'
GEOHASH_DECODEDecode a GeoHash to longitude/latitudeGEOHASH_DECODE('ucfv0nzpt3s7')[37.7950, 55.7129]

H3 Cell Properties

FunctionDescriptionExample
H3_GET_RESOLUTIONReturn the resolution of an H3 indexH3_GET_RESOLUTION(644325524701193974)15
H3_GET_BASE_CELLReturn the base cell numberH3_GET_BASE_CELL(644325524701193974)14
H3_IS_VALIDCheck whether an H3 index is validH3_IS_VALID(644325524701193974)TRUE
H3_IS_PENTAGONCheck whether an H3 index is a pentagonH3_IS_PENTAGON(644325524701193974)FALSE
H3_IS_RES_CLASS_IIICheck whether an H3 index is class IIIH3_IS_RES_CLASS_III(644325524701193974)FALSE
H3_GET_FACESReturn intersecting icosahedron facesH3_GET_FACES(644325524701193974)[7]
H3_TO_PARENTReturn the parent index at a lower resolutionH3_TO_PARENT(644325524701193974, 10)622236721289822207
H3_TO_CHILDRENReturn child indexes at a higher resolutionH3_TO_CHILDREN(622236721289822207, 11)[...]
H3_TO_CENTER_CHILDReturn the center child for a resolutionH3_TO_CENTER_CHILD(622236721289822207, 11)625561602857582591
H3_CELL_AREA_M2Return the area of a cell in square metersH3_CELL_AREA_M2(644325524701193974)0.8953
H3_CELL_AREA_RADS2Return the area of a cell in square radiansH3_CELL_AREA_RADS2(644325524701193974)2.2e-14
H3_HEX_AREA_KM2Return the average hexagon area in km²H3_HEX_AREA_KM2(10)0.0152
H3_HEX_AREA_M2Return the average hexagon area in m²H3_HEX_AREA_M2(10)15200
H3_TO_GEO_BOUNDARYReturn the boundary of a cellH3_TO_GEO_BOUNDARY(644325524701193974)[[lon1,lat1], ...]
H3_NUM_HEXAGONSReturn the number of hexagons at a resolutionH3_NUM_HEXAGONS(2)5882

H3 Neighborhoods

FunctionDescriptionExample
H3_DISTANCEReturn the grid distance between two indexesH3_DISTANCE(599119489002373119, 599119491149856767)1
H3_INDEXES_ARE_NEIGHBORSTest whether two indexes are neighborsH3_INDEXES_ARE_NEIGHBORS(599119489002373119, 599119491149856767)TRUE
H3_K_RINGReturn all indexes within k distanceH3_K_RING(599119489002373119, 1)[599119489002373119, ...]
H3_HEX_RINGReturn indexes exactly k steps awayH3_HEX_RING(599119489002373119, 1)[599119491149856767, ...]
H3_LINEReturn indexes along a pathH3_LINE(from_h3, to_h3)[from_h3, ..., to_h3]

H3 Edge Operations

FunctionDescriptionExample
H3_GET_UNIDIRECTIONAL_EDGEReturn the edge between two adjacent cellsH3_GET_UNIDIRECTIONAL_EDGE(from_h3, to_h3)edge_index
H3_UNIDIRECTIONAL_EDGE_IS_VALIDCheck whether an edge index is validH3_UNIDIRECTIONAL_EDGE_IS_VALID(edge_index)TRUE
H3_GET_ORIGIN_INDEX_FROM_UNIDIRECTIONAL_EDGEReturn the origin cell from an edgeH3_GET_ORIGIN_INDEX_FROM_UNIDIRECTIONAL_EDGE(edge_index)from_h3
H3_GET_DESTINATION_INDEX_FROM_UNIDIRECTIONAL_EDGEReturn the destination cell from an edgeH3_GET_DESTINATION_INDEX_FROM_UNIDIRECTIONAL_EDGE(edge_index)to_h3
H3_GET_INDEXES_FROM_UNIDIRECTIONAL_EDGEReturn both cells for an edgeH3_GET_INDEXES_FROM_UNIDIRECTIONAL_EDGE(edge_index)[from_h3, to_h3]
H3_GET_UNIDIRECTIONAL_EDGES_FROM_HEXAGONList edges originating from a cellH3_GET_UNIDIRECTIONAL_EDGES_FROM_HEXAGON(h3_index)[edge1, edge2, ...]
H3_GET_UNIDIRECTIONAL_EDGE_BOUNDARYReturn the boundary of an edgeH3_GET_UNIDIRECTIONAL_EDGE_BOUNDARY(edge_index)[[lon1,lat1], [lon2,lat2]]

H3 Measurements & Angles

FunctionDescriptionExample
H3_EDGE_LENGTH_KMReturn the average edge length in kilometresH3_EDGE_LENGTH_KM(10)0.065
H3_EDGE_LENGTH_MReturn the average edge length in metresH3_EDGE_LENGTH_M(10)65.91
H3_EXACT_EDGE_LENGTH_KMReturn the exact edge length in kilometresH3_EXACT_EDGE_LENGTH_KM(edge_index)0.066
H3_EXACT_EDGE_LENGTH_MReturn the exact edge length in metresH3_EXACT_EDGE_LENGTH_M(edge_index)66.12
H3_EXACT_EDGE_LENGTH_RADSReturn the exact edge length in radiansH3_EXACT_EDGE_LENGTH_RADS(edge_index)0.00001
H3_EDGE_ANGLEReturn the angle in radians between two edgesH3_EDGE_ANGLE(edge1, edge2)1.047