4

enter image description here

I would like to select the largest number in a column of an attribute table by "Select by attributes" in QGIS to select the polygon with the largest area. How would be the expression for that? I do not want to sort the column and select the polygon per hand, because I want to use it in the modeler.

1

1 Answer 1

10

You would be better off using "Select by expression" instead of "Select by attribute". Your expression should be something like:

"AREA" = maximum("AREA")

Replace "AREA" in the expression with the name of the column.

Alternatives are:

$area = maximum($area)

or

area($geometry) = maximum(area($geometry))

For more details about the difference between $area and area($geometry), please refer to this thread: Calculating polygon areas in shapefile using QGIS.

For example, the following screenshot shows how to select the polygon with the maximum value of the "POP_EST" field using "Select by expression" from the Processing Toolbox (Ctrl+Alt+T).

enter image description here

7
  • Unfortunatly using this expression throws the error: "syntax error, unexpected '(', expecting $end". I tried replacing maximum with max, but then the whole area is selected.
    – Moo
    Feb 27, 2017 at 11:52
  • Can you share the screenshot of the window where you are using the expression and the error is occurring?
    – nash
    Feb 27, 2017 at 14:54
  • I added the screenhot above. A Layer with the polygons; B Attribute Table; C Select by Expression Window; D Expression; E Processing Window; F Error Message;
    – Moo
    Feb 27, 2017 at 16:10
  • Try using the expression without the quotations ". Something like AREA = maximum(AREA)
    – nash
    Feb 27, 2017 at 16:36
  • Now the error message changed in " Error executing algorithm Select by expression syntax error, unexpected EQ, expecting '(' "
    – Moo
    Feb 27, 2017 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.