[GIS] Calculate distance between 2 points following a path in QGIS

distancelinepointqgisrouting

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 ?

Best Answer

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)

enter image description here

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.

enter image description here

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:

enter image description here

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.