This topic describes the ST_LineInterpolatePoint function. This function interpolates a point at the specified location of a LineString object and returns the point.
Syntax
geometry ST_LineInterpolatePoint(geometry aLinestring , float8 aFraction);
geography ST_LineInterpolatePoint(geography aLinestring , float8 aFraction);
Parameters
Parameter | Description |
aLinestring | The LineString object that you want to specify. |
aFraction | The fraction based on which the point is interpolated into the line. The value of this parameter is a floating-point number within the range of 0 to 1. |
Description
The function supports 3D objects and does not delete z coordinates.
The function supports m coordinates.
If the geographic coordinate system is used, the distance between points is calculated based on the spherical distance.
Examples
Obtain the coordinate of the central point in a specified line segment.
SELECT ST_AsText(ST_LineInterpolatePoint(geom, 0.5)) FROM (SELECT 'LINESTRING(0 0,2 2)'::geometry as geom) As test; st_astext ------------ POINT(1 1) (1 row) SELECT ST_AsText(ST_LineInterpolatePoint(geog, 0.5)) FROM (SELECT 'LINESTRING(0 0,2 2)'::geography as geog) As test; ------------------------------------------ POINT(0.99969732796684 1.00015638159834)
Obtain the point that is closest to a geometry object on a line.
SELECT ST_AsText(ST_LineInterpolatePoint(geom, ST_LineLocatePoint(geom, 'POINT(1 1)'::geometry))) FROM (SELECT 'LINESTRING(0 0,0 2)'::geometry As geom) As test; st_astext ------------ POINT(0 1) (1 row) -- geography SELECT ST_AsText(ST_LineInterpolatePoint(geog, ST_LineLocatePoint(geog, 'POINT(1 1)'::geography))) FROM (SELECT 'LINESTRING(0 0,0 2)'::geography As geog) As test; --------------------------- POINT(0 1.00015229710421)