ST_LineInterpolatePoint
Inserts a point object at a specified location on a LineString and returns the point.
Syntax
geometry ST_LineInterpolatePoint(geometry aLinestring , float8 aFraction);
geography ST_LineInterpolatePoint(geography aLinestring , float8 aFraction);
Parameters
|
Parameter |
Description |
|
aLinestring |
The target LineString object. |
|
aFraction |
The percentage along the line segment at which the point is inserted. The value is a floating-point number from 0 to 1. |
Description
-
This function supports 3D objects and does not delete the z coordinate.
-
This function supports M coordinates.
-
If a geographic coordinate system is used, the calculation is based on the spheroidal distance.
Example
-
Calculate the coordinates of the midpoint of a given 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 on a line that is closest to a geometry object:
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)