Applies to:
Databricks Runtime 17.1 and above
ST geospatial functions operate on objects of type GEOGRAPHY
and/or GEOMETRY
, or allow to construct GEOGRAPHY
and GEOMETRY
values from standard or popular geospatial formats, or export GEOGRAPHY
and GEOMETRY
values to standard or popular geospatial formats.
See also:
Import Databricks functions to get ST functions (Databricks Runtime)
No import needed for Databricks SQL and Spark SQL.
To import ST functions for Python or Scala in notebooks, use the following commands:
Python
from pyspark.databricks.sql import functions as dbf
Scala
import com.databricks.sql.functions._
List of ST geospatial functions (Databricks SQL)
Import
Function |
Description |
st_geogfromgeojson(geojsonExpr) |
Returns a GEOGRAPHY(4326) value from its GeoJSON representation. |
st_geogfromtext(wktExpr) |
Returns a GEOGRAPHY(4326) value from its WKT representation. |
st_geogfromwkb(wktExpr) |
Returns a GEOGRAPHY(4326) value from its WKB representation. |
st_geogfromwkt(wktExpr) |
Returns a GEOGRAPHY(4326) value from its WKT representation. |
st_geomfromewkb(wktExpr) |
Returns a GEOMETRY(ANY) value from its EWKB representation. |
st_geomfromgeohash(geohash) |
Returns the geohash grid box corresponding to the input geohash value as a 2D polygon geometry. |
st_geomfromgeojson(geojsonExpr) |
Returns a GEOMETRY(4326) value from its GeoJSON representation. |
st_geomfromtext(wktExpr[, sridExpr]) |
Returns a GEOMETRY(srid) or GEOMETRY(ANY) value from its WKT representation, and sets its SRID value to the value of sridExpr , or 0 if sridExpr is omitted. |
st_geomfromwkb(wkbExpr[, sridExpr]) |
Returns a GEOMETRY(srid) or GEOMETRY(ANY) value from its WKB representation, and sets its SRID value to the value of sridExpr , or 0 if sridExpr is omitted. |
st_geomfromwkt(wktExpr[, sridExpr]) |
Returns a GEOMETRY(srid) or GEOMETRY(ANY) value from its WKT representation, and sets its SRID value to the value of sridExpr , or 0 if sridExpr is omitted. |
st_pointfromgeohash(geohash) |
Returns the center of the geohash grid box corresponding to the input geohash value as a 2D point geometry. |
to_geography(georepExpr) |
Returns a GEOGRAPHY(ANY) value from its GeoJSON, WKB, or WKT representation. |
to_geometry(georepExpr) |
Returns a GEOMETRY(ANY) value from its EWKB, GeoJSON, WKB, or WKT representation. |
try_to_geography(georepExpr) |
Returns a GEOGRAPHY(ANY) value from its GeoJSON, WKB, or WKT representation, or NULL if the input representation is invalid. |
try_to_geometry(georepExpr) |
Returns a GEOMETRY(ANY) value from its EWKB, GeoJSON, WKB, or WKT representation, or NULL if the input representation is invalid. |
Export
Function |
Description |
st_asbinary(geoExpr) |
Returns the WKB representation of the input GEOGRAPHY or GEOMETRY value as a BINARY value. |
st_asewkb(geoExpr) |
Returns the EWKB representation of the input GEOMETRY value as a BINARY value. |
st_asgeojson(geoExpr) |
Returns the GeoJSON representation of the input GEOGRAPHY or GEOMETRY value as a STRING value. |
st_asewkt(geoExpr) |
Returns the EWKT representation of the input GEOGRAPHY or GEOMETRY value as a STRING value. |
st_astext(geoExpr) |
Returns the WKT representation of the input GEOGRAPHY or GEOMETRY value as a STRING value. |
st_aswkb(geoExpr) |
Returns the WKB representation of the input GEOGRAPHY or GEOMETRY value as a BINARY value. |
st_aswkt(geoExpr) |
Returns the WKT representation of the input GEOGRAPHY or GEOMETRY value as a STRING value. |
st_geohash(geo [, precision]) |
Returns the geohash of the input geometry at the given precision. |
Measurements
Constructors
Function |
Description |
st_makeline(geoArray) |
Returns a linestring GEOMETRY whose points are the non-empty points of the geometries in the input array of geometries, which are expected to be points, linestrings, or multipoints. |
st_makepolygon(outer[, innerArray]) |
Constructs a polygon GEOMETRY from the input outer boundary and optional array of inner boundaries, represented as closed linestrings. |
st_point(x, y [, srid]) |
Returns a point GEOMETRY with the given x and y coordinates and SRID value (if provided). |
Accessors
Function |
Description |
st_dimension(geoExpr) |
Returns the topological dimension of the 2D projection of the GEOMETRY . |
st_endpoint(geoExpr) |
Returns the last point of the input GEOGRAPHY or GEOMETRY value, if the input geospatial value is a non-empty linestring. |
st_envelope(geoExpr) |
Returns a 2D Cartesian geometry representing the 2D axis-aligned minimum bounding box (envelope) of the input geometry. |
st_envelope_agg(geoCol) |
Returns the envelope of all the geometries in the column, or NULL if the column has zero rows, or contains only NULL values. |
st_geometryn(geo, n) |
Returns the 1-based n-th element of the input geometry as a GEOMETRY value. |
st_geometrytype(geoExpr) |
Returns the type of the input GEOGRAPHY or GEOMETRY value as a string. |
st_isempty(geoExpr) |
Returns true if the input GEOGRAPHY or GEOMETRY value does not contain any non-empty points. |
st_m(geoExpr) |
Returns the M coordinate of the input point GEOMETRY , or NULL if the point is empty or does not have an M coordinate. |
st_ndims(geoExpr) |
Returns the coordinate dimension of the input GEOGRAPHY or GEOMETRY value. |
st_npoints(geoExpr) |
Returns the number of non-empty points in the input GEOGRAPHY or GEOMETRY value. |
st_numgeometries(geoExpr) |
Returns the number of geometries in the input GEOMETRY value. |
st_pointn(geoExpr, indexExpr) |
Returns the n-th point from the input linestring GEOGRAPHY or GEOMETRY . |
st_startpoint(geoExpr) |
Returns the first point of the input GEOGRAPHY or GEOMETRY value, if the input geospatial value is a non-empty linestring. |
st_x(geoExpr) |
Returns the X coordinate of the input point GEOMETRY , or NULL if the point is empty. |
st_xmax(geoExpr) |
Returns the maximum X coordinate of the input GEOMETRY , or NULL if the geometry is empty. |
st_xmin(geoExpr) |
Returns the minimum X coordinate of the input GEOMETRY , or NULL if the geometry is empty. |
st_y(geoExpr) |
Returns the Y coordinate of the input point GEOMETRY , or NULL if the point is empty. |
st_ymax(geoExpr) |
Returns the maximum Y coordinate of the input GEOMETRY , or NULL if the geometry is empty. |
st_ymin(geoExpr) |
Returns the minimum Y coordinate of the input GEOMETRY , or NULL if the geometry is empty. |
st_z(geoExpr) |
Returns the Z coordinate of the input point GEOMETRY , or NULL if the point is empty or does not have a Z coordinate. |
st_zmax(geoExpr) |
Returns the maximum Z coordinate of the input GEOMETRY , or NULL if the geometry is empty or does not have a Z coordinate. |
st_zmin(geoExpr) |
Returns the minimum Z coordinate of the input GEOMETRY , or NULL if the geometry is empty or does not have a Z coordinate. |
Editors
Geometry Validation
Function |
Description |
st_isvalid(geoExpr) |
Returns true if the input GEOMETRY is a valid geometry in the OGC sense. |
Spatial Reference System Functions
Function |
Description |
st_setsrid(geo, srid) |
Returns a new GEOMETRY value whose SRID is the specified SRID value. |
st_srid(geoExpr) |
Returns the SRID of the input GEOGRAPHY or GEOMETRY value. |
st_transform(geo, srid) |
Transforms the X and Y coordinates of the input GEOMETRY from the current coordinate reference system to the coordinate reference system described by the provided SRID value. |
Distance Relationships
Function |
Description |
st_dwithin(geo1, geo2, d) |
Returns true if the 2D Cartesian distance between the two input geometries is smaller than or equal to the input distance. |
Topological Relationships
Overlay Functions
Function |
Description |
st_rotate(geoExpr, rotationAngle) |
Rotates the input GEOMETRY around the Z axis by the given rotation angle (in radians). |
st_scale(geoExpr, xfactor, yfactor[, zfactor]) |
Scales the input GEOMETRY in the X, Y, and, if specified, Z directions using the provided scaling factors. |
st_translate(geoExpr, xoffset, yoffset[, zoffset]) |
Translates the input GEOMETRY in the X, Y, and, if specified, Z directions using the provided offsets. |
Geometry Processing