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.
Function | Syntax |
---|---|
Python | shortest |
SQL | ST |
Scala | shortest |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for shortest_line.
Examples
from geoanalytics_fabric.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)
+-----------------------------+
|shortest_line |
+-----------------------------+
|{"paths":[[[30,25],[20,25]]]}|
+-----------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |