Returns the 2D point on g1 that is closest to g2.
Syntax
geometry ST_ClosestPoint(geometry g1, geometry g2);Parameters
| Parameter | Description |
|---|---|
| g1 | The first geometry object. |
| g2 | The 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)