# ST_ClosestPoint

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.

FunctionSyntax
Python`closest_point(geometry1, geometry2)`
SQL`ST_ClosestPoint(geometry1, geometry2)`

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

### Examples

PythonPythonSQL
Use dark colors for code blocksCopy
``````from geoanalytics.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()
``````
Result
Use dark colors for code blocksCopy
``````+---------------+
|  closest_point|
+---------------+
|{"x":20,"y":20}|
+---------------+``````

### Version table

ReleaseNotes

1.1.0

Function introduced