# QGIS 3x calculate distance between two points with coordinates

I have a problem, very similar to Calculating distance between two points with coordinates using ArcGIS Desktop where I would like to calculate the distance between two polygons (circles) with their coordinates defined by a centroid function in the field calculator.

I found some possible options to calculate the distance between them:

1. with Python console: where it looks like I should do the calculation point by point
2. Distance matrix - not really applicable in y case, as I have the polygons instead of points
3. NNjoin plugin - it looks like some layers must be merged, I don't want that
4. GRASS v.distance - I used it, but I am getting an error as you see below.

1. I also used the following formula:

``````  distance((\$geometry),geometry(get_feature_by_id('Area9_Poles', 1)))
``````

https://stackoverflow.com/questions/63231575/calculate-distance-between-two-points-in-qgis-field-calculator

but it gives me the cumulative distance from one point only.

So, the distance is calculated always from P1. If you look at the image above you will get my point. In the Distance [meters] column I need the calculation: from P1 to P2 distance (which is correct) from P2 to P3 distance, which is not correct, because it's calculated from P1 to P3 and gives 47m, whereas it is 27.

What is missing in this formula then?

How can I calculate the distance consequently from the last point instead of the very first one?

My full data attribute table is below:

• Have you had a look at `join by nearest`? It should do, what you're looking for.
– Erik
Sep 29, 2020 at 10:19
• I found sth like this: geomnearest(Area_9 Area9_Poles) Sep 29, 2020 at 10:23
• Yes indeed. I already attached my data attribute table, you can see. I need the distance calculation from p1 to p2, from p2 to p3 and so on, based on the geometry (XY coordinates). All elements are tagged in the fid order (1st column). Sep 29, 2020 at 11:04
• As per the Help please Do not use signature, taglines, or greetings in your posts. An example of a greeting is "Good morning".
– PolyGeo
Oct 1, 2020 at 0:17