# Calculate distance between 2 points following a path in QGIS

I'm currently working on bird's data. I have coordinates of observation points and I'd like to measure the distance between points following a path. The given bird is probably moving from point to point therefore euclidean distance between 2 points is probably far from real distances.

Let's imagine I have 3 sites : A,B and C. B is between A and C: For going from A to C, the bird walk A → B → C so the distance AC is given by the sum of distances AB + BC.

I'm looking for the mean of getting quickly all possible distances: AB, BC and AC. I'm used to QGIS.

Of course, I could simply do the sum of euclidean distances myself but I have 15 points so it would be so long to get the distances for all points' couple.

Do you have an idea of how to do it automatically ?

• how do you know which Sites the bird pass through ? did you define a relationship between Sites ? Nov 1, 2017 at 7:20
• We sampled droppings and get genetic's information from it. So we have identity of individuals, date of sampling and site of sampling. The sampling points are mostly following crest line. So, in order to determine the distance between the points, I have to sum the euclidean distances "point to point". Nov 3, 2017 at 15:48
• Based on distance matrix you will able to know all of distance couples, but this doesn't give you total lenght of any possible path. You need to manually define the step ordering of the path and then perform the sql query (in answer) for exemple to get what you want. Nov 3, 2017 at 22:26

Another approach by a `Virtual Layer`.

Given you are working on avian movement, I assumed the data is on geographical coordinates (LatLong).

1) Created a dummy data.(The layer name is `PointLayer1`) 2) `Layer | Add Layer | Add Virtual Layer`

• Import the `PointLayer1`
• Write query to measure distance between each stop:

Query:

``````SELECT a.loc AS A, b.loc AS B, ROUND(st_distance(a.geometry, b.geometry, 4326) / 1000, 3) AS EACH_km
FROM PointLayer1 a
INNER JOIN PointLayer1 b ON a.loc = b.loc -1
ORDER BY a.loc
``````

Which gives a virtual layer (please open the attribute table) with each flight distance (kilometers) between A and B. As you need the total flight length, modify the syntax slightly to:

``````SELECT total(EACH_km) AS TOTAL_km
FROM
(SELECT a.loc AS A, b.loc AS B, ROUND(st_distance(a.geometry, b.geometry, 4326) / 1000, 3) AS EACH_km
FROM PointLayer1 a  INNER JOIN PointLayer1 b
ON a.loc = b.loc -1
ORDER BY a.loc)
``````

It will give you something like: When you use the syntax, please replace the `PointLayer1` by your layer, and `loc` by your field to identify the order of stop points.

3) Run scenarios

You can modify order of points by changing `loc` field. When you change the `loc` then the virtual layer will update the calculation.

Go to `Vector / Analysis Tools / Distance Matrix`. From there, select your point layer as both the input and target layers.