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
Pythonclosest_point(geometry1, geometry2)
SQLST_ClosestPoint(geometry1, geometry2)
ScalaclosestPoint(geometry1, geometry2)

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

Examples

PythonPythonSQLScala
1
2
3
4
5
6
7
8
9
10

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
1
2
3
4
5
+---------------+
|  closest_point|
+---------------+
|{"x":20,"y":20}|
+---------------+

Version table

ReleaseNotes

1.1.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close