3

I have two point layers. One of biological records which has an attribute field for the SiteID that the species has been found at. The second layer is a Sites layer with a centroid location for that site. I want to find the distance between each record and the centroid of its linked site to check for bad georeferencing i.e. the larger the distance, the more likely that the record has been given a bad location.

I was trying to use the Field Calculator in QGIS using the following algorithm:

shortest_line($geometry, geometry(get_feature('Sites', 'id', "SiteID")))

Where "SiteID" is the field in the Records layer that has the ID of the site I want to measure the distance between the record and the site centroid. But this is not working so I think the problem is how I have entered the field in the Records layer that contains the ID to look up in the Sites layer.

Can anyone help please?

4
  • Are you aware of transform() function? i.e. shortest_line(transform($geometry, 'EPSG:ORIGIN', 'EPSG:TARGET'), geometry(get_feature('Sites', 'id', "SiteID")))
    – Taras
    Mar 22 '21 at 12:33
  • 4
    What do you mean by "But this is not working"? To get the distance of your line you need to add length(shortest_line(...))
    – MrXsquared
    Mar 22 '21 at 12:59
  • Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works
    – Ian Turton
    Mar 22 '21 at 13:40
  • Thank you MrXsquared - missing out "length" was my obvious mistake. Solved now!
    – davidm06
    Mar 22 '21 at 17:57
1

shortest_line() returns a geometry of type LineString. To measure the distance of this line you create in your expression, you need to add length():

length(shortest_line($geometry, geometry(get_feature('Sites', 'id', "SiteID"))))

You could also measure the distance between two points directly by using distance(<point1_geom>,<point2_geom>)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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