ST_GeodesicShortestLine

ST_GeodesicShortestLine takes two geometry columns and returns a linestring column. The output column contains the shortest line that touches two geometries, using geodesic distance calculation. This function returns only one shortest line if there are more than one. If the two input geometries intersect, an empty line geometry is returned.

This function is more accurate but less performant than ST_ShortestLine and requires that a spatial reference is set on the input geometry column. If the two geometry columns are in different spatial references, the function automatically transforms the second geometry into the spatial reference of the first. To learn more about the difference between planar and geodesic calculations, see Coordinate systems and transformations.

FunctionSyntax
Pythongeodesic_shortest_line(geometry1, geometry2)
SQLST_GeodesicShortestLine(geometry1, geometry2)
ScalageodesicShortestLine(geometry1, geometry2)

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

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
from geoanalytics.sql import functions as ST

line_text = 'LINESTRING (-117.61983168124925 34.061452833142205, -117.13262450694835 34.198818997647145, -117.0291395187358 34.01338533049988)'
point_text = 'POINT (-117.34805417060637 34.00267278771285)'
df = spark.createDataFrame([(line_text, point_text)], ["line_wkt", "point_wkt"]) \
          .withColumn("line", ST.line_from_text("line_wkt", 4326)) \
          .withColumn("point", ST.point_from_text("point_wkt", 4326))

df.select(ST.geodesic_shortest_line("line", "point").alias("geodesic_shortest_line")).show(truncate = False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+---------------------------------------------------------------------------------------------+
|geodesic_shortest_line                                                                       |
+---------------------------------------------------------------------------------------------+
|{"paths":[[[-117.39749505040815,34.12413977992499],[-117.34805417060637,34.00267278771285]]]}|
+---------------------------------------------------------------------------------------------+

Version table

ReleaseNotes

1.1.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.