ST_GeodesicDistance

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.

FunctionSyntax
Pythongeodesic_distance(geometry1, geometry2)
SQLST_GeodesicDistance(geometry1, geometry2)
ScalageodesicDistance(geometry1, geometry2)

For more details, go to the GeoAnalytics Engine API reference for geodesic_distance.

This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from geoanalytics.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()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+-----------------+
|geodesic_distance|
+-----------------+
|              0.0|
|           1000.0|
|           2486.0|
+-----------------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.