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.

Taras
  • 32,823
  • 4
  • 66
  • 137
Moo
  • 171
  • 2
  • 11

1 Answers1

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

Taras
  • 32,823
  • 4
  • 66
  • 137
nash
  • 1,976
  • 14
  • 19
  • 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 like AREA = 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 $area=maximum($area) directly in your expression.

    – nash Feb 27 '17 at 22:22