ST_DumpSegments
Name
ST_DumpSegments — Returns a set of
geometry_dump
rows for the segments in a geometry.
Synopsis
geometry_dump[]
ST_DumpSegments
(
geometry
geom
)
;
Description
A set-returning function (SRF) that extracts the segments of a geometry.
It returns a set of
geometry_dump
rows,
each containing a geometry (
geom
field)
and an array of integers (
path
field).
-
the
geom
fieldLINESTRING
s represent the segments of the supplied geometry. -
the
path
field (aninteger[]
) is an index enumerating the segment start point positions in the elements of the supplied geometry. The indices are 1-based. For example, for aLINESTRING
the paths are{i}
wherei
is thenth
segment start point in theLINESTRING
. For aPOLYGON
the paths are{i,j}
wherei
is the ring number (1 is outer; inner rings follow) andj
is the segment start point position in the ring.
Availability: 3.2.0
This function supports Triangles and Triangulated Irregular Network Surfaces (TIN).
This function supports 3d and will not drop the z-index.
Standard Geometry Examples
SELECT path, ST_AsText(geom) FROM ( SELECT (ST_DumpSegments(g.geom)).* FROM (SELECT 'GEOMETRYCOLLECTION( LINESTRING(1 1, 3 3, 4 4), POLYGON((5 5, 6 6, 7 7, 5 5)) )'::geometry AS geom ) AS g ) j; path │ st_astext --------------------------------- {1,1} │ LINESTRING(1 1,3 3) {1,2} │ LINESTRING(3 3,4 4) {2,1,1} │ LINESTRING(5 5,6 6) {2,1,2} │ LINESTRING(6 6,7 7) {2,1,3} │ LINESTRING(7 7,5 5) (5 rows)
TIN and Triangle Examples
-- Triangle -- SELECT path, ST_AsText(geom) FROM ( SELECT (ST_DumpSegments(g.geom)).* FROM (SELECT 'TRIANGLE(( 0 0, 0 9, 9 0, 0 0 ))'::geometry AS geom ) AS g ) j; path │ st_astext --------------------------------- {1,1} │ LINESTRING(0 0,0 9) {1,2} │ LINESTRING(0 9,9 0) {1,3} │ LINESTRING(9 0,0 0) (3 rows)
-- TIN -- SELECT path, ST_AsEWKT(geom) FROM ( SELECT (ST_DumpSegments(g.geom)).* FROM (SELECT 'TIN((( 0 0 0, 0 0 1, 0 1 0, 0 0 0 )), (( 0 0 0, 0 1 0, 1 1 0, 0 0 0 )) )'::geometry AS geom ) AS g ) j; path │ st_asewkt --------------------------------- {1,1,1} │ LINESTRING(0 0 0,0 0 1) {1,1,2} │ LINESTRING(0 0 1,0 1 0) {1,1,3} │ LINESTRING(0 1 0,0 0 0) {2,1,1} │ LINESTRING(0 0 0,0 1 0) {2,1,2} │ LINESTRING(0 1 0,1 1 0) {2,1,3} │ LINESTRING(1 1 0,0 0 0) (6 rows)