跳到主要内容

Geometry Functions

This page provides a comprehensive overview of Geometry functions in Databend, organized by functionality for easy reference.

Geometry Creation Functions

FunctionDescriptionExample
ST_MAKEGEOMPOINT / ST_GEOM_POINTConstructs a Point geometryST_MAKEGEOMPOINT(-122.35, 37.55)POINT(-122.35 37.55)
ST_MAKELINE / ST_MAKE_LINECreates 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_MAKEPOLYGONCreates a Polygon from a LineStringST_MAKEPOLYGON(ST_MAKELINE(...))POLYGON(...)
ST_POLYGONCreates a PolygonST_POLYGON(...)POLYGON(...)

Geometry Conversion Functions

FunctionDescriptionExample
ST_GEOMETRYFROMTEXT / ST_GEOMFROMTEXTConverts WKT to geometryST_GEOMETRYFROMTEXT('POINT(-122.35 37.55)')POINT(-122.35 37.55)
ST_GEOMETRYFROMWKB / ST_GEOMFROMWKBConverts WKB to geometryST_GEOMETRYFROMWKB(...)POINT(...)
ST_GEOMETRYFROMEWKT / ST_GEOMFROMEWKTConverts EWKT to geometryST_GEOMETRYFROMEWKT('SRID=4326;POINT(-122.35 37.55)')POINT(-122.35 37.55)
ST_GEOMETRYFROMEWKB / ST_GEOMFROMEWKBConverts EWKB to geometryST_GEOMETRYFROMEWKB(...)POINT(...)
ST_GEOMFROMGEOHASHConverts GeoHash to geometryST_GEOMFROMGEOHASH('9q8yyk8')POLYGON(...)
ST_GEOMPOINTFROMGEOHASHConverts GeoHash to PointST_GEOMPOINTFROMGEOHASH('9q8yyk8')POINT(...)
TO_GEOMETRYConverts various formats to geometryTO_GEOMETRY('POINT(-122.35 37.55)')POINT(-122.35 37.55)

Geometry Output Functions

FunctionDescriptionExample
ST_ASTEXTConverts geometry to WKTST_ASTEXT(ST_MAKEGEOMPOINT(-122.35, 37.55))'POINT(-122.35 37.55)'
ST_ASWKTConverts geometry to WKTST_ASWKT(ST_MAKEGEOMPOINT(-122.35, 37.55))'POINT(-122.35 37.55)'
ST_ASBINARY / ST_ASWKBConverts geometry to WKBST_ASBINARY(ST_MAKEGEOMPOINT(-122.35, 37.55))WKB representation
ST_ASEWKTConverts geometry to EWKTST_ASEWKT(ST_MAKEGEOMPOINT(-122.35, 37.55))'SRID=4326;POINT(-122.35 37.55)'
ST_ASEWKBConverts geometry to EWKBST_ASEWKB(ST_MAKEGEOMPOINT(-122.35, 37.55))EWKB representation
ST_ASGEOJSONConverts geometry to GeoJSONST_ASGEOJSON(ST_MAKEGEOMPOINT(-122.35, 37.55))'{"type":"Point","coordinates":[-122.35,37.55]}'
ST_GEOHASHConverts geometry to GeoHashST_GEOHASH(ST_MAKEGEOMPOINT(-122.35, 37.55), 7)'9q8yyk8'
TO_STRINGConverts geometry to stringTO_STRING(ST_MAKEGEOMPOINT(-122.35, 37.55))'POINT(-122.35 37.55)'

Geometry Properties

FunctionDescriptionExample
ST_DIMENSIONReturns the dimension of a geometryST_DIMENSION(ST_MAKEGEOMPOINT(-122.35, 37.55))0
ST_SRIDReturns the SRID of a geometryST_SRID(ST_MAKEGEOMPOINT(-122.35, 37.55))4326
ST_NPOINTS / ST_NUMPOINTSReturns the number of points in a geometryST_NPOINTS(ST_MAKELINE(...))2
ST_XReturns the X coordinate of a PointST_X(ST_MAKEGEOMPOINT(-122.35, 37.55))-122.35
ST_YReturns the Y coordinate of a PointST_Y(ST_MAKEGEOMPOINT(-122.35, 37.55))37.55
ST_XMINReturns the minimum X coordinateST_XMIN(ST_MAKELINE(...))-122.40
ST_XMAXReturns the maximum X coordinateST_XMAX(ST_MAKELINE(...))-122.35
ST_YMINReturns the minimum Y coordinateST_YMIN(ST_MAKELINE(...))37.55
ST_YMAXReturns the maximum Y coordinateST_YMAX(ST_MAKELINE(...))37.60
ST_LENGTHReturns the length of a LineStringST_LENGTH(ST_MAKELINE(...))5.57

Geometry Accessors

FunctionDescriptionExample
ST_POINTNReturns a specific Point from a LineStringST_POINTN(ST_MAKELINE(...), 1)POINT(-122.35 37.55)
ST_STARTPOINTReturns the first Point of a LineStringST_STARTPOINT(ST_MAKELINE(...))POINT(-122.35 37.55)
ST_ENDPOINTReturns the last Point of a LineStringST_ENDPOINT(ST_MAKELINE(...))POINT(-122.40 37.60)

Spatial Operations

FunctionDescriptionExample
ST_DISTANCEReturns the distance between two geometriesST_DISTANCE(ST_MAKEGEOMPOINT(-122.35, 37.55), ST_MAKEGEOMPOINT(-122.40, 37.60))5.57
HAVERSINEReturns the great-circle distance between two pointsHAVERSINE(37.55, -122.35, 37.60, -122.40)6.12
ST_CONTAINSChecks if one geometry contains anotherST_CONTAINS(ST_MAKEPOLYGON(...), ST_MAKEGEOMPOINT(...))TRUE
ST_TRANSFORMTransforms geometry from one SRID to anotherST_TRANSFORM(ST_MAKEGEOMPOINT(-122.35, 37.55), 3857)POINT(-13618288.8 4552395.0)
ST_SETSRIDSets the SRID of a geometryST_SETSRID(ST_MAKEGEOMPOINT(-122.35, 37.55), 3857)POINT(-122.35 37.55)