1

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.

2

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

  • I don't know why, but this expression doesn't works. It says 'invalid expression. – caio villaca Apr 16 at 19:59
  • I updated my answer. The issue was that I used $z, which calculates the z coordinate value of a 3D point. I missed the fact that your z values are stored as attributes, so I should have used "z". – csk Apr 16 at 20:05
  • Now is selecting all the points.. LOL. Don't know what I'm doing wrong – caio villaca Apr 16 at 20:17
  • 1
    You're not doing anything wrong, I'm just not on top of my game today. Updated again. Now it should select the point with the highest Z in each group. – csk Apr 16 at 20:26
  • That worked hahah Thanks! It was so simple. I need to study more about the sintax. :) – caio villaca Apr 17 at 0:19
1

SQL is the answer !

You can achieve this using the DB Manager of QGIS.

You choose Database / Database Manager / Database Manager then Virtual Layers / Qgis Layers you can then try queries like the following :

SELECT max(Z), pt_x, pt_y FROM my_table group by ID

You can then load the result in the layer manager.

  • Thanks a lot. This expression worked here. But I need a way to automatize this. Is ti possible to create a plugin with DB Manager and use it on Graphical modeler? 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. – caio villaca Apr 16 at 20:02
  • 2
    You should edit your question then and give all the elements u need right from the start ... – snaileater Apr 16 at 20:04
  • sorry, I edited my question . Thanks for the help – caio villaca Apr 16 at 20:16
  • what do u call your 'process' ? U don't give any information + there's nothing 'manual' in the 2 solutions that have been given to u ... – snaileater Apr 16 at 20:20
  • It is a lot of steps conected on graphical modeler. My question here is just one of these steps. So, all the steps togethers are my process that will be repeated hundreds of times – caio villaca Apr 16 at 20:23

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.