Returns a substring of a LineString between two fractional positions along its length.
Syntax
geometry ST_LineSubstring(geometry aLinestring, float8 startfraction, float8 endfraction);
geography ST_LineSubstring(geography aLinestring, float8 startfraction, float8 endfraction);Parameters
| Parameter | Type | Description |
|---|---|---|
aLinestring | geometry / geography | The input LineString. |
startfraction | float8 | The start position. |
endfraction | float8 | The end position. |
Usage notes
Equal fractions: If
startfractionandendfractionare equal, the function behaves the same as ST_LineInterpolatePoint.MultiLineString:
ST_LineSubstringoperates on a singleLineString. To extract a substring from aMultiLineString, first merge its component lines withST_LineMerge.3D and M coordinates: The function preserves z and m coordinates.
geometry vs. geography: The
geometryvariant measures fractions along a planar (straight-line) path. Thegeographyvariant measures along the spheroid surface, so the interpolated coordinates differ even for the same input.
Examples
Geometry
Extract the middle 30% of a line (from 30% to 60% of its length):
SELECT ST_AsText(ST_LineSubstring('LINESTRING(0 0,10 10)'::geometry, 0.3, 0.6));
st_astext
---------------------
LINESTRING(3 3,6 6)
(1 row)Geography
The same fractions applied to a geography object return spheroid-interpolated coordinates:
SELECT ST_AsText(ST_LineSubstring('LINESTRING(0 0,10 10)'::geography, 0.3, 0.6));
st_astext
--------------------------------------------------------------------------------
LINESTRING(2.97227762767668 3.01417970957332,5.96094221033023 6.0199989936211)What's next
ST_LineInterpolatePoint — Returns a single point at a fractional position along a line.