Home > Software design >  Split Geometry / LineString by vertex and not on intersect
Split Geometry / LineString by vertex and not on intersect

Time:12-23

I would like to cut the lines by vertex. It does not work as I wish because there are lines that cross. The current query that I split the lines by vertex and also as soon as the lines intersect. I only want it to cut at vertices and not at line crossings. Thank you enter image description here Here is the SQL

WITH gpx_line AS (
SELECT uuid, ST_AsText(ST_MakeLine(lag((pt).geom, 1, NULL) OVER (PARTITION BY uuid ORDER by uuid, (pt).path), (pt).geom)) AS wkb_geometry
  FROM (SELECT uuid, ST_DumpPoints(wkb_geometry) AS pt FROM public.points_gpx_to_line) as dumps
)
SELECT * FROM gpx_line WHERE wkb_geometry IS NOT NULL;  

CodePudding user response:

Without sample data and the expected results it is hard to know for sure what you're trying to achieve, but I believe what you described can be done with ST_DumpSegments:

A set-returning function (SRF) that extracts the coordinates (vertices) of a geometry. It returns a set of geometry_dump rows, each containing a geometry (geom field) and an array of integers (path field).

SELECT 
  ST_AsText(
   (ST_DumpSegments('LINESTRING(1 1,2 2,3 3,4 4)'::geometry)).geom);
      st_astext      
---------------------
 LINESTRING(1 1,2 2)
 LINESTRING(2 2,3 3)
 LINESTRING(3 3,4 4)
(3 rows)
  • Related