Sunday 15 July 2018

qgis - Selecting features in attribute table using maximum aggregate function


I have a table containing distances from one ID (an address) to another ID (bus stops).


There table contains distances from all addresses to all different bus stops.


Now I want to select the feature where the distance between the certain address and the bus stop is the shortest.


In QGIS I've tried to do something like this:


enter image description here


where:




  • "meter" is the distance column;

  • "fromID" is the address.


There are 16 different addresses and a little more than 6000 features in the table. What I need is a table with only 16 features.


You can, of course, use minimum function as well.


Can anybody help out here?



Answer



You can use the following expression in the Select by Expression tool:


"meter" = maximum( "meter", "fromID" )


This selects all "meter" values which equals the maximum "meter" value found for each "fromID" group.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...