Interpolates a point at one or more specified locations of a LineString object and returns the points.
Syntax
geometry ST_LineInterpolatePoints(geometry aLinestring, float8 aFraction, boolean repeat);
geography ST_LineInterpolatePoints(geography aLinestring, float8 aFraction, boolean repeat);Parameters
| Parameter | Type | Description |
|---|---|---|
aLinestring | geometry / geography | The LineString to interpolate along. |
aFraction | float8 | The fraction based on which the point is interpolated into the line. Valid values: floating-point numbers in the range 0 to 1. |
repeat | boolean | Specifies whether to generate points at every interval along the line. Default value: true. When set to false, at most one point is returned. |
Usage notes
When
repeatistrue, the function places a point at every location that is represented as a fraction along the line.If the result contains zero or one point, the return type is
Point. If the result contains more than one point, the return type isMultiPoint.3D geometries are supported. Z coordinates are preserved in the output.
M coordinates are supported.
For the
geographyoverload, distances are calculated using spherical distance rather than planar distance.
Examples
Interpolate points every 20% along a line (geometry)
SELECT ST_AsText(ST_LineInterpolatePoints('LINESTRING(0 0,0 5)', 0.20));Result:
MULTIPOINT(0 1,0 2,0 3,0 4,0 5)
(1 row)Interpolate points every 20% along a line (geography)
SELECT ST_AsText(ST_LineInterpolatePoints('LINESTRING(0 0,0 5)'::geography, 0.20));Result:
MULTIPOINT((0 1.00002443285827),(0 2.00004274948544),(0 3.00004884128919),(0 4.00003661494431),(0 5))Return a single point with repeat set to false (geometry)
SELECT ST_AsText(ST_LineInterpolatePoints('LINESTRING(0 0,0 5)', 0.20, false));Result:
POINT(0 1)
(1 row)Return a single point with repeat set to false (geography)
SELECT ST_AsText(ST_LineInterpolatePoints('LINESTRING(0 0,0 5)'::geography, 0.20, false));Result:
POINT(0 1.00002443285827)
(1 row)