ST_Distance takes two geometry columns and returns a double column. The output column represents the planar distance between the two input geometries. For multipoints, lines, and polygons, the distance is calculated from the nearest point between the geometries. The result will be in the same units as the input geometry data. For example, if your input geometries are in a spatial reference that uses meters, the result values will be in meters.
If the two geometry columns are in different spatial references, the function will automatically transform the second geometry into the spatial reference of the first.
If your input geometries are in a geographic coordinate system, use ST_GeodesicDistance to calculate distance.
For more details, go to the GeoAnalytics Engine API reference for distance.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.
from geoanalytics.sql import functions as ST, Point data = [ (Point(-176, -15), Point(-176, -15)), (Point(-176, -15), Point(-176, -20)), (Point(-176, -15), Point(-175, -15)) ] df = spark.createDataFrame(data, ["point1", "point2"]) df.select(ST.distance("point1", "point2").alias("distance")).show()
+--------+ |distance| +--------+ | 0.0| | 5.0| | 1.0| +--------+