6

I have a road network and different points connected to the roads. I would like to measure the distance between several points along the roads.

Basically I want to do the same like the Road Graph Plugin, but I want to measure not only the distance between two points and also would like to get the results in an attribute table.

2
  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq.
    – underdark
    Commented Mar 11, 2016 at 20:35
  • Perhaps this post might help: QGIS calculate distance of point along a line.
    – Joseph
    Commented Mar 14, 2016 at 12:58

1 Answer 1

5

I first thought this question was basically same as another recent question Points layer distance from the start of line layer in QGIS.

However, there is an added complexity in this one, that OP requires distance between (not a distance from the start point).

So I needed QGIS 3.0 get_feature_by_id() function to calculate the difference between records.

(1) Calculate the distance of each point along the line, from the start point of the line.

Please see Points layer distance from the start of line layer in QGIS

(2) Calculate distance between points, based on the distance taken from previous step (1).

Again, open the attribute table of Points layer, which has distance field.

Create a new field interval by the below expression:

  attribute(get_feature_by_id('Points', $id+1), 'distance')
  - attribute(get_feature_by_id('Points', $id), 'distance')

This expression calculates the difference between points by (value at next row minus value at current row).

NB: The $id is unrelated to id field shown in the picture. Sorry if it is confusing.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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