Fork me on GitHub

ST_ProjectPoint

Signatures

GEOMETRY ST_ProjectPoint(GEOMETRY geomA, GEOMETRY geomB);

Description

Project a POINT (geomA) along a LINESTRING (geomB). If the POINT projected is out of the LINESTRING the first (or last) POINT on the LINESTRING will be returned, otherwise the input POINT.

Examples

SELECT ST_PROJECTPOINT('POINT(1 2)',
                       'LINESTRING(0 0, 4 2)') as THE_GEOM;
-- Answer: POINT (1.6 0.8)

SELECT ST_PROJECTPOINT('POINT(1 2)',
                       'MULTILINESTRING ((0 0, 4 2), (1 4, 2 2))') as THE_GEOM;
-- Answer: POINT (1.8 2.4)

SELECT ST_PROJECTPOINT('POINT(4 3)',
                       'LINESTRING (0 0, 4 2)') as THE_GEOM;
-- Answer: POINT (4 2)

SELECT ST_PROJECTPOINT('POINT(4 3)',
                       'POLYGON ((2 4, 0 2, 3 0, 2 4))') as THE_GEOM;
-- Answer: NULL

See also