ST_ClosestPoint — Returns the 2-dimensional point on g1 that is closest to g2. This is the first point of the shortest line.
geometry ST_ClosestPoint(
geometry
g1, geometry
g2)
;
Returns the 2-dimensional point on g1 that is closest to g2. This is the first point of the shortest line.
Availability: 1.5.0
SELECT ST_AsText(ST_ClosestPoint(pt,line)) AS cp_pt_line, ST_AsText(ST_ClosestPoint(line,pt)) As cp_line_pt FROM (SELECT 'POINT(100 100)'::geometry As pt, 'LINESTRING (20 80, 98 190, 110 180, 50 75 )'::geometry As line ) As foo; cp_pt_line | cp_line_pt ----------------+------------------------------------------ POINT(100 100) | POINT(73.0769230769231 115.384615384615)
|
SELECT ST_AsText( ST_ClosestPoint( ST_GeomFromText('POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))'), ST_Buffer(ST_GeomFromText('POINT(110 170)'), 20) ) ) As ptwkt; ptwkt ------------------------------------------ POINT(140.752120669087 125.695053378061)
|