ST_GeodesicDistance takes two geometry columns and returns a double column. The output column represents the geodesic distance between the two input geometries in meters. For multipoints, lines, and polygons, the distance is calculated from the nearest point between the geometries. This function is more accurate but less performant than ST_Distance and requires that a spatial reference is set on at least the first input geometry column. To learn more about the difference between planar and geodesic calculations see Coordinate systems and transformations.
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.
Function | Syntax |
---|---|
Python | geodesic |
SQL | ST |
Scala | geodesic |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for geodesic_distance.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.
Examples
from geoanalytics_fabric.sql import functions as ST, Point
from pyspark.sql import functions as F
data = [
(Point(-2500000, 8100000), Point(-2500000, 8100000)),
(Point(-2500000, 8100000), Point(-2501000, 8100000)),
(Point(-2500000, 8100000), Point(-2501000, 8101000))
]
df = spark.createDataFrame(data, ["point1", "point2"])\
.withColumn("point1", ST.srid("point1", 54008))\
.withColumn("point2", ST.srid("point2", 54008))
df.select(F.round(ST.geodesic_distance("point1", "point2"), 0).alias("geodesic_distance")).show()
+-----------------+
|geodesic_distance|
+-----------------+
| 0.0|
| 1000.0|
| 2486.0|
+-----------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |