QGIS Attribute Selection – Selecting Highest Value Within Group

attribute-tableqgisselect

I have a .shp of points. This points are organized in groups with same ID (group 1, 2 ,3)

Each group has 10 points.

Each point has a Z column with Z values.

I want to select the point with the highest Z value for each group.

So just one point should be selected for each group.

I was trying "select by expression" but I don't know what expression to use.

Also, I need a way to automatize this. This process is just a small part of my project that needs to be repeated a bunch of times, so doing this manually all the time is impossible. A way to use do this with graphical modeler would be great.

Best Answer

Select by Expression using this expression to select the point with the highest Z value for each ID group:

"z" = maximum("z","ID")

function maximum Returns the aggregate maximum value from a field or expression.

Syntax maximum(expression[,group_by][,filter])

[ ] marks optional components

Arguments

expression sub expression of field to aggregate

group_by optional expression to use to group aggregate calculations

filter optional expression to use to filter features used to calculate aggregate

Example: maximum("population",group_by:="state") → maximum population value, grouped by state field

Related Question