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.
Asked
Active
Viewed 2,169 times
4
-
Please, do not forget about "What should I do when someone answers my question?" – Taras Dec 06 '21 at 07:29
1 Answers
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).
-
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 '17 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 '17 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 '17 at 16:10
-
Try using the expression without the quotations
". Something likeAREA = maximum(AREA)– nash Feb 27 '17 at 16:36 -
Now the error message changed in " Error executing algorithm Select by expression syntax error, unexpected EQ, expecting '(' " – Moo Feb 27 '17 at 21:07
-
Can you share the version of QGIS you are using and on which platform?
Also, I'd like to suggest instead of using field calculator to add a column for area you can skip that step and use the expression
– nash Feb 27 '17 at 22:22$area=maximum($area)directly in your expression. -

