PostGISGeometry Accessors

ST_DumpSegments

What is ST_DumpSegments?

ST_DumpSegments is a set-returning PostGIS function (added in 3.2) that decomposes a geometry into its individual line segments, yielding one row per segment as a two-point LINESTRING. Each row carries a path describing its position within the source geometry.

SQL
ST_DumpSegments(geometry g) → setof geometry_dump(path integer[], geom geometry)

Applies to any geometry with edges — linestrings, polygons, and their multi variants. Point geometries produce no output.

When would you use ST_DumpSegments?

Use ST_DumpSegments when per-segment analysis matters — computing segment-level bearings, detecting the longest edge in a polygon, or stitching attributes per edge in routing and network QC tasks:

SQL
1SELECT track_id, (s).path[1] AS seg_idx,
2       ST_Length((s).geom) AS seg_len,
3       degrees(ST_Azimuth(ST_StartPoint((s).geom), ST_EndPoint((s).geom))) AS bearing
4FROM (
5  SELECT track_id, ST_DumpSegments(geom) AS s FROM tracks
6) t;

Before PostGIS 3.2 the same analysis required pairing ST_DumpPoints with a lead/lag join; ST_DumpSegments is the direct replacement.

FAQs

What geometry types does ST_DumpSegments accept?

Any input with edges — LINESTRING, POLYGON, MULTILINESTRING, MULTIPOLYGON, and collections containing them. Pure points produce no rows.

What does each segment look like?

Each emitted geom is a LINESTRING with exactly two vertices — the start and end of that segment, in the original coordinate order.

How does the path array index segments?

Mirrors the vertex path conventions: for a LINESTRING, path = '{segment_number}'; for a POLYGON, path = '{ring_number, segment_number}'; and so on.

Which PostGIS version added ST_DumpSegments?

PostGIS 3.2. On older versions use ST_DumpPoints with a self-join on consecutive paths to reconstruct segments manually.