# How to calculate distances in QGIS field calculator?

So I'm using qgis 2.6.0 and I have a csv (converted into a .shp) with two geometry columns, I want to create a new column with the distance between the two geometry:

``````shot.lat    shot.lon    haul.lat    haul.lon
57.563      -12.986     57.534      -12.985
57.7        -13.304     57.67       -13.299
57.611      -13.529     57.582      -13.538
57.594      -13.294     57.565      -13.315
57.432      -13.314     57.402      -13.304
57.339      -13.053     57.311      -13.072
``````

I am trying to use the function geometry function "distance" with the following expression:

``````distance( geomFromWKT( 'POINT("shot.lon" "shot.lat")' ) , geomFromWKT('POINT( "haul.lon" "haul.lat")' ))
``````

This should then create a new field with the distance between the points. When it runs though, it just returns Null. Am I missing something obvious?

``````'POINT("shot.lon" "shot.lat")'
``````

Try:

``````'POINT(' + "shot.lon" + ' ' + "shot.lat" +')'
``````

EDIT - However - for your example, that will only give you distance in degrees. This will work for projected coordinates (UTM, for example) but not decimal degrees.

• Will `distance()` return correct result for the degrees input? `distance: returns the minimum distance (based on spatial ref) between two geometries in projected units` – SS_Rebelious Nov 13 '14 at 11:32
• No, definitely won't - was suggesting corrected code in a hurry, forgot to add that part. – Simbamangu Nov 14 '14 at 7:02
• I think there is something wrong in the formula. When you paste this formula you can end up with an error `Parser Error: Eval Error: Cannot convert POINT(' to double`. It should with string concatenation `||` like `distance(geom_from_wkt('POINT(' + "X1" || ' ' || "Y1" + ')'), geom_from_wkt('POINT(' + "X2" || ' ' || "Y2" +')'))` – Taras Dec 4 '18 at 14:50