Returns a float8 value between 0 and 1 representing the relative position of the closest point on a LineString to a given point, as a fraction of the total line length.
Syntax
float8 ST_LineLocatePoint(geometry aLinestring , geometry aPoint);
float8 ST_LineLocatePoint(geography aLinestring , geography aPoint);Parameters
| Parameter | Description |
|---|---|
aLinestring | The LineString object. |
aPoint | The point object. |
Usage notes
A common use case is approximating street address numbers along a road segment.
Examples
geometry variant — returns an exact fraction based on planar distance:
SELECT ST_LineLocatePoint('LINESTRING(0 0,0 2)'::geometry, 'POINT(1 1)'::geometry);
st_linelocatepoint
--------------------
0.5
(1 row)geography variant — returns a fraction based on spheroidal distance; the result differs slightly from the planar result because the Earth is not flat:
-- geography
SELECT ST_LineLocatePoint('LINESTRING(0 0,0 2)'::geography, 'POINT(1 1)'::geography);
st_linelocatepoint
--------------------
0.5000746195163556
(1 row)