Name

ST_Line_Locate_Point — Computes de fraction of a Line from the closest point on the line to the given point.

Synopsis

double ST_Line_Locate_Point(bytea Line, bytea Point);

Alias

Line_Locate_Point

Description

Computes de fraction of a Line from the closest point on the line to the given point.

The point does not necessarily have to lie precisely on the line. Both geometries must have the same SRID and dimensions.

Coordinate Dimensions
2D3DM

-

-

Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

SELECT ST_Line_Locate_Point(ST_GeomFromEWKT('LINESTRING (29 35, 29 21, 11 21)'),ST_GeomFromEWKT('POINT (20 28)'));
--Result
0.71875

-- Using ST_Line_Interpolate_Point (see graphic below)
SELECT ST_AsText(ST_Line_Interpolate_Point(line,ST_Line_Locate_Point(line,point))) as interpolate 
FROM (SELECT ST_GeomFromText('LINESTRING (10 11, 15 26, 29 35)') as line, 
      ST_GeomFromText('POINT (27 27)') as point) 
as foo;

--Result
                  interpolate
-----------------------------------------------
 POINT (23.945848375451263 31.750902527075812)
(1 row)
2nd example, finds closest point from a Line to a given point

Related functions

ST_Line_Interpolate_Point, ST_Project_Point