Share via


st_closestpoint

Important

This feature is in Public Preview. You can confirm preview enrollment on the Previews page. See Manage Azure Databricks previews.

Returns the 2D projection of a point on the first geometry that is closest to the second geometry with respect to the Euclidean distance.

For the corresponding Databricks SQL function, see st_closestpoint function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.st_closestpoint(col1=<col1>, col2=<col2>)

Parameters

Parameter Type Description
col1 pyspark.sql.Column or str The first Geometry value.
col2 pyspark.sql.Column or str The second Geometry value.

Notes

The two geometries are expected to have the same SRID value, otherwise an error is returned. The SRID value of the returned point is the same as the common SRID value of the input geometries. Returns the 2D empty point if any of the two input geometries is empty.

Examples

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOINT ZM (-10 10 -1 -10,2 10 -2 -20,20 10 -3 -30)','POINT Z (0 0 300)',)], ['wkt1', 'wkt2'])
df.select(dbf.st_asewkt(dbf.st_closestpoint(dbf.st_geomfromtext('wkt1', 3857), dbf.st_geomfromtext('wkt2', 3857)).alias('result'))).collect()
[Row(result='SRID=3857;POINT(2 10)')]