ST_ClosestPoint takes two geometry columns and returns a point column. The output column returns the point on the first geometry that is the closest to the second geometry. ST_ClosestPoint calculates the planar distance to identify the closest point on the first geometry in relation to the second geometry. Consider using ST_GeodesicClosestPoint if you would like to obtain the closest point by calculating the geodesic distance to the second geometry. To learn more about the difference between planar and geodesic calculations see Coordinate systems and transformations. If the two input geometry columns are in different spatial references, the spatial reference of the output geometry would be the same as the first geometry.
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.
Function | Syntax |
---|---|
Python | closest |
SQL | ST |
Scala | closest |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for closest_point.
Examples
from geoanalytics_fabric.sql import functions as ST
line_text = 'LINESTRING (30 10, 10 30, 40 40)'
df = spark.createDataFrame([(line_text, 10, 10)], ["wkt", "lon", "lat"]) \
.withColumn("line", ST.line_from_text("wkt")) \
.withColumn("point", ST.point("lon", "lat"))
df.select(ST.closest_point("line", "point").alias("closest_point")).show()
+---------------+
| closest_point|
+---------------+
|{"x":20,"y":20}|
+---------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |