ST_ShortestLine

ST_ShortestLine takes two geometry columns and returns a linestring column. The output column contains the shortest line that touches two geometries, using planar 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. If the two geometry columns are in different spatial references, the function automatically transforms the second geometry into the spatial reference of the first.

If your input geometries are in a geographic coordinate system, consider using ST_GeodesicShortestLine to identify the shortest line.

FunctionSyntax
Pythonshortest_line(geometry1, geometry2)
SQLST_ShortestLine(geometry1, geometry2)
ScalashortestLine(geometry1, geometry2)

For more details, go to the GeoAnalytics Engine API reference for 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 (30 10, 30 40)'

df = spark.createDataFrame([(line_text, 20, 25)], ["wkt", "lon", "lat"]) \
          .withColumn("line", ST.line_from_text("wkt")) \
          .withColumn("point", ST.point("lon", "lat"))

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

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.