Extracting a section of LineString

LineStrings can be sliced not only using other geometries, but also based on a fraction of their length. This is done by the ST_LineSubstring function. It accepts three arguments: an input geometry, which must be a LineString (a MultiLineString must be merged using ST_LineMerge), the starting fraction, and the ending fraction. For example, we can extract the first half of the Odra river as follows:

SELECT ST_LineSubstring(     (SELECT ST_LineMerge(ST_Collect(wkb_geometry)) FROM lines WHERE name='Odra' AND waterway='river'),     0,     0.5 )  
A line cut in half with an ST_LineSubstring

When distance values are needed, ...

Get Mastering PostGIS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.