4

I have a point vector with features sharing non-unique "ID"s. Each feature also has a "distance" field. I want to select among each set of features sharing the same "ID" only the feature with the minimum value.

Example:

row ID Distance
1 One 3.4
2 One 1.6
3 Two 5.4
4 Two 6.8

From the above, it should select rows 2 and 3.

I have seen similar questions that ask for the minimum value for each "ID", but I want to select the whole feature (because I need the coordinates of the feature).

I also know that this problem is trivially handled with VLOOKUP in Excel, but I want to streamline my workflow and so I am looking for a solution within QGIS.

1
  • 1
    Once you have the ID and min distance it is trivial to select the matching feature
    – Ian Turton
    Dec 30 '20 at 18:05
5

Use select by expression with this expression:

"Distance"=minimum( "Distance", "ID")

enter image description here

3
  • Thank you. I had tried to use that tool, but my expression was: minimum("Distance", "ID"). I didn't know I needed to add the '"Distance" =' part in front of it, so it didn't work.
    – Selenium
    Dec 30 '20 at 18:43
  • Your expression selects the smallest Distance, grouped per ID. You now select all rows where this value is equal to the respective Distance
    – Babel
    Dec 30 '20 at 18:54
  • You're welcome. As a new user, please be adviced that this side tries to avoid "thank you" messages. Instead, it encourages you to accept the answer: click the checkmark right to the answer to accept it, see: meta.stackexchange.com/questions/5234/… and gis.stackexchange.com/help/someone-answers
    – Babel
    Dec 30 '20 at 18:58

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.