ST_GeodesicClosestPoint takes two geometry columns and returns a point column. The output column returns the point on the first geometry that is closest to the second geometry, using geodesic distance calculation. This function returns only one geodesic closest point if there are more than one. If the two input geometries intersect, an empty point 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.
This function is more accurate but less performant than ST_ClosestPoint and requires that a spatial reference is set on the input geometry column. To learn more about the difference between planar and geodesic calculations, see Coordinate systems and transformations.
Function | Syntax |
---|---|
Python | geodesic |
SQL | ST |
Scala | geodesic |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for geodesic_closest_point.
Examples
from geoanalytics_fabric.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_closest_point("line", "point").alias("geodesic_closest_point")).show(truncate = False)
+-----------------------------------------------+
|geodesic_closest_point |
+-----------------------------------------------+
|{"x":-117.39749505040815,"y":34.12413977992499}|
+-----------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |