I am trying to calculate the distance between the green points and the red point on their left and add that distance to the green points attributes.

The lines are roads and I made the red dots using the QChainage extension. I then added the roads ID to the red dots. After that I tried to calculate the distance using the Distance Matrix but the results weren't the one I expected.

Is there another way I could get the distance between the points and the point to their left?

enter image description here

  • Do the green dots have an attribute field to identify the target red dot?
    – Kazuhito
    Jun 24, 2020 at 10:30
  • Yes, they have a unique ID in common Jun 24, 2020 at 12:27

1 Answer 1


Some assumptions:

  • Red: The layername of the red points
  • id: The unique id field in the Red layer.
  • Green: The layername of the green points
  • red_id: An identifier which suggests the point in Red layer. This corresponds to id in the Red layer.


  1. Open attribute table of the Green layer and start the Field Calculator.
  2. Create a new field dist (or something like that) with an expression distance($geometry, geometry(get_feature('Red', 'id', "red_id")))

Hope this helps. Please modify the attribute names as required.

  • Thank you very much, it worked! I will just need to fix a few things with my red dots and I will have the results I needed Jun 24, 2020 at 14:38

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.