3

I have dropped a GPS breadcrumb track (.gpx format) onto my project. If I generate a a virtual field in this layer to calculate the distance between successive crumbs using the expression:

distance(($geometry),geometry(get_feature_by_id( @layer_name, $id+1)))

I get totally misleading results. Why is this? And is there anyway around it without saving the GPX file as a projected shapefile and redoing the calculation (which then works fine)?

2
  • What is misleading about the results?
    – Matt
    Commented Feb 14, 2022 at 20:42
  • they are blatantly incorrect - points that are far from the next point do not necessarily have greater values than points that are close. The values calculated are decimal (0.02-0.07) whereas the actual distance between pairs ranges from 1 to about 1200m
    – Albert
    Commented Feb 14, 2022 at 20:55

1 Answer 1

5

The small values are likely because the CRS of GPX files is WGS84 (measured in degrees, not meters). In which case you will need to transform the points to a projected coordinate system.

Something like:

distance(transform($geometry, 'EPSG:4326', 'EPSG:32735'), transform(geometry(get_feature_by_id( @layer_name, $id+1)), 'EPSG:4326', 'EPSG:32735'))

Although this may be slow, depending how many points you have.


The problem with the calculated distances not corresponding with what you see on the map is that the points might not be ordered 1 to 1 with $id and timestamp. It is hard to tell without seeing your data.

4
  • The transformation resulted in values now in the range of 10-9500 (ie now too big!) and still bearing no correspondence with actual spacing (ie large spacing does not necessarily have large values).
    – Albert
    Commented Feb 14, 2022 at 21:27
  • I made a calculated field to show $id and this is correct - 1st record has $id 1, second $id 2 etc
    – Albert
    Commented Feb 14, 2022 at 21:28
  • The fact that it all works when saved as a shapefile makes me think that you are in the right track and its to do with transformation and CRS. The CRS of my project is EPSG:32737
    – Albert
    Commented Feb 14, 2022 at 21:30
  • The expression is now as follows, but I still get misleading results: distance(transform($geometry, 'EPSG:4326', 'EPSG:32737'), transform (geometry(get_feature_by_id( @layer_name, $id+1)), 'EPSG:4326', 'EPSG:32737'))
    – Albert
    Commented Feb 15, 2022 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.