I have a poly line layer where each feature has a Geometric Length and numerical ID. Some of these IDs are duplicates. I would like to be able to select the longest line from each set of duplicates to create a new layer with just the unique IDs.

1 Answer 1


QGIS 2.18 case:

  1. Open attribute table
  2. Activate Select by expression
  3. Type $length = maximum($length, group_by:= "id")
  4. Click on [Select]
  5. Save As... (Save only selected features)
  • Thank you. I didn't know about 'group_by'.
    – Steve H
    Oct 2, 2017 at 2:33
  • Thanks @SteveH , Yes Aggregates group is relatively new Changelog for QGIS 2.16. I think they are extremely useful.
    – Kazuhito
    Oct 2, 2017 at 2:44

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.