ST_LineExtend
What is ST_LineExtend?
ST_LineExtend lengthens a LineString at its start, end, or both endpoints by specified distances, following the direction of the nearest segment. Available from PostGIS 3.4.
ST_LineExtend(geometry line, float distance_forward, float distance_backward = 0.0) → geometryDistances are in the units of the geometry's SRID. A zero distance disables extension on that side.
When would you use ST_LineExtend?
Use ST_LineExtend to project a line beyond its original endpoints — for instance, extending a street centreline to intersect a wider right-of-way boundary, or projecting a property setback to confirm it hits a neighbouring feature. It is also useful for generating search corridors in the direction of travel for a known track.
In infrastructure planning, extending centrelines by a small margin before buffering ensures that connectivity tests at junctions succeed despite small digitizing gaps.
FAQs
What direction does the extension follow?
The extension continues along the direction of the last segment at each end. Curved or meandering lines are not reprojected beyond the straight extrapolation.
Does it work on closed LineStrings or rings?
The function accepts closed LineStrings but extending them produces geometry that usually no longer closes. Most users should call it only on open lines.
What units are used?
The CRS's native units — metres for projected SRIDs like EPSG:3857, degrees for EPSG:4326. Transform to a projected CRS before calling for metric-accurate extension.
What version introduced ST_LineExtend?
PostGIS 3.4. For older versions, compute new endpoints manually using ST_Azimuth and ST_Project, then rebuild with ST_MakeLine.