All Products
Search
Document Center

PolarDB:ST_ClosestPoint

Last Updated:Mar 28, 2026

Returns the 2D point on g1 that is closest to g2.

Syntax

geometry ST_ClosestPoint(geometry g1, geometry g2);

Parameters

ParameterDescription
g1The first geometry object.
g2The second geometry object.

Description

ST_ClosestPoint returns the point on g1 that minimizes the distance to g2. The returned point is the end point of the shortest line between g1 and g2.

Examples

SELECT ST_AsText(ST_ClosestPoint('LINESTRING(0 -1,0 1)'::geometry,'POINT(1 0)'::geometry));
 st_astext
------------
 POINT(0 0)
(1 row)