SELECT a column
FROM a table, the column value(s) are made available to functions, either per row, or as aggregates. Function results can be passed consecutively into enclosing functions.
In this case you would simply
SELECT ST_AsText(ST_Segmentize(geom::GEOGRAPHY, 50)) AS geom
Note that I use a cast (
GEOGRAPHY; since you intent to use meter as distance threshold, you either need your geometries projected in a suitable CRS (with meter as unit), or the
GEOGRAPHY type, which implicitly uses meter as unit; this only works on geographic reference systems, and the cast assumes EPSG:4326 (WGS84) as the default.
ST_Segmentize only inserts vertices to ensure no two vertices are further apart than the given threshold (the definition of a segment is a geometry part between two vertices)!
To obtain individual geometries representing parts of your 'segments' with a max. length, you'd need to get more involved; there is no simple command as of yet.
There are multiple possibilities, e.g.:
- create line 'segments' from the densified lines (following the usage of
ST_Segmentize above); you'd get 'segments' with arbitrary lines not longer than the threshold given to
- create line 'segments' of fixed length, using
ST_LineSubstring; well defined line length, e.g. you could find a length that divides a line equally
For your case (initial two-vertice 'segments' will have segments with exactly 50m length, except the last one with up to 50m length), the first approach should work just fine:
densified AS (
SELECT <id>, -- ROW_NUMBER() OVER() AS id
ST_AsText(ST_Segmentize(geom, 50)) AS geom
SELECT id AS line_id,
path AS segment_id,
ST_MakeLine(dmp.geom, LEAD(dmp.geom) OVER(PARTITION BY d.id ORDER BY dmp.path)) AS geom
FROM densified AS d,
LATERAL ST_DumpPoints(d.geom) AS dmp
WHERE geom IS NOT NULL
Don't forget to replace
<id> with the actual id column of your table, or use the commented out
Note that I do not use a cast to
GEOGRAPHY, since your mentioned CRS is a metric projection already.