# Calculating 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 geometries:

``````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` Commented Nov 13, 2014 at 11:32
• No, definitely won't - was suggesting corrected code in a hurry, forgot to add that part. Commented Nov 14, 2014 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" +')'))` Commented Dec 4, 2018 at 14:50