Distance between two points - by ID in QGIS

I have a dataset of 350 or so individuals. Each individual has a start point (2 columns with Lat and Long) and end point (2 columns with Lat and Long). I would like calculate the distance between these in QGIS and have the output as a new column in the data set. (so for each row calculate the distance between two points)

Now - I have achieved this in the R statistical package pretty easily with the following code:

library(geosphere)

Dataset\$distance<-distVincentyEllipsoid(Dataset[,c('gps.of.start.point_e','gps.of.start.point_s')], bb[,c('gps.of.end_e','gps.of.end_s')]

What I have tried so far in QGIS: I can create two point layers - "start points" and "end points" and use a distance matrix to calculate the distances between points. I get the data I want but also get thousands of permutations that I am not interested in and so sorting them and extraction them for my data set is time consuming and difficult.

Is there an easier way of doing this in QGIS?

Assuming your data structure is like below

id, start_x, start_y, end_x, end_y

This is straighforward in QGIS if you have data in a projected CRS. You can add your text file as a vector layer, and add a virtual field in the Field Calculator with the extression such as below.

distance(make_point( "start_x" , "start_y" ), make_point( "end_x" , "end_y" ))

The caveat is that this will be the distance in the units of layer CRS, which from your question is WGS84 (you are using gps coordinates) and thus distance will be in degrees. If you want ellipsoidal distance in meters, there is a longer way.

1. Add your table to QGIS as a vector layer
2. Use 'Create point layer from table' algorithm and select 'start_x' and 'start_y' as you X and Y fields. Name the layer 'start'
3. Use 'Create point layer from table' algorithm and select 'end_x' and 'end_y' as you X and Y fields. Name the layer 'end'
4. Use 'Join by Lines (hub lines)' algorithm. Select 'start' as your hub layer and 'end' as your spoke layer. Keep 'id' as both hub and spoke ids.
5. Now you have lines joining your start and end points.
6. Open Field Calculator and add a virtual field with the expression \$length. You will get a new column for each line which will have distance in meters. • Perfect - thank you very much – AdSad Aug 30 at 8:18