The algorithm might be looking like this one
WITH RECURSIVE generate_points(sec) AS (
SELECT conf.starting_point
FROM conf
UNION ALL
SELECT sec + conf.step
FROM generate_points, conf
WHERE sec + conf.step <= conf.num_segments
),
conf AS (
SELECT SUM(ST_NPoints(geometry)) AS num_points,
SUM(ST_NPoints(geometry)) - 1 AS num_segments,
1 AS starting_point,
1 AS step
FROM lines)
SELECT gs.sec AS sec,
ROUND(ST_Distance(ST_PointN(l.geometry,sec),
ST_PointN(l.geometry,sec + conf.step)),2) AS distance,
sec AS point_from,
sec + conf.step AS point_to
FROM generate_points AS gs, lines AS l, conf
WHERE sec + conf.step <= num_points
GROUP BY gs.sec
Tested on QGIS 2.18 and QGIS 3.4 by means of a "Virtual Layer"
through Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume there is a line layer called "lines"
, see image below.
Note: The length in the above attribute table is wrong. It was previously calculated for a different line and was not updated afterwards.
With the above Query, it is possible to return distances between backward and forward points of the line string.
The output will look as following
References:
D1
is a distance between pointsC2
andC1
?