2

The data of interest: a point vector and a line vector. Both shapefiles, with the line vector acting as the road/motorway. All of the points are along the road so close by.

I want to calculate the distance from point to point but the points are not necessarily in order in terms of their spatial representation.

What I mean by this is that point 64 is one the right side of the road, while point 65 on the left side of the road (I have attributes for that, road, side). E.g. id 65 might not be the next point after 64 so as in a straight line.

So far, I have tried to use distance matrix but that doesn't take into account the motorway direction (line vector).

Any ideas what to do next?

2

I would suggest a two-step approach, but this is probably a bit awkward.

[Step 1]

Calculate distance from the start of the line to each point.

(1) Assume the Line layer has known unique id field for each line.

(2) Open the attribute table of the Points layer and create a new field dist by an expression:

line_locate_point(geometry(get_feature('Line', 'id', '1')), $geometry)

[Step 2]

Use virtual layer to create a table of distances between all point pair combinations.

The syntax would be:

SELECT a.id AS starts, b.id AS ends, ABS(a.dist - b.dist) AS delta
FROM Points AS a, Points AS b
WHERE a.id <> b.id

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.