# How can I calculate different polygons by different attributes?

I'm doing my master thesis and want to calculate different polygons (in QGIS 1.8 for Mac) in four different columns which I defined by different attributes. i.e. some of the attributes in the first column are named "1112" and some "1113",.... So how can I calculate the area of the polygons in column "1" with the attributes "1112"?

The numbers here are only examples, my thesis is about greenspaces, so it would be to complicate to explain here...all of the numbers have a different meaning and have to be joined. I need to sum these attributes to make a statement for the thesis.

Markus

@M_Gebhart

• Welcome to gis.stackexchange! Not sure if I was able to understand your problem. Do you want to calculate the area of all the polygons that, in the attribute (or field) called "1", have the value 1112? Commented Jul 9, 2013 at 13:56
• I think seeing a screenshot of part of your attribute table would help. Commented Jul 9, 2013 at 14:50
• Did you tried the Plugin "GroupStat"?
– user19908
Commented Jul 9, 2013 at 15:01

You can use an if/then statement, that might be easiest. See this answer for more info: https://gis.stackexchange.com/a/39170

Right click the layer and Open Attribute Table.

Start editing by clicking the Toggle Editing Mode button, or CTRL+E.

In the field calculator window, you can either Create a new field or Update existing field depending on where you're at in your analysis.

What's useful for this method, is that you can group up all of your conditions into a single statement (modify below as needed)...

``````CASE WHEN FIELD1 IN ( 1112, 1115 ) THEN \$area
WHEN FIELD2 = 1117 THEN \$area
WHEN FIELD3 >= 1110 THEN \$area
ELSE ''
END
``````

..replacing FIELDn with your actual fields that have those values and the numbers to actual values you need to calculate the area for. The \$area function will output the area automatically in the units or your data's projection (feet, metres etc).

NOTE: If your values in Field1 are stored as text/strings and not numbers/integers, then they need to be enclosed in single quotes in the query so use something like: `CASE WHEN FIELD1 IN ( '1112', '1115' )`

You should also update the comparison used: `IN, =, >=` to whatever you need in each WHEN.

If you want calculate some values for each entities in Quantum GIS you can open the Attribute Table then :

A :"toggle edition mode" B :"Open field calculator"

You can then calculate what you want. an exemple to create a new field (area - a_value_in_a_field) below : - select create new field

and click on ok...

It's not totally clear what you are looking for, but to me it sounds like the Group Stats plugin would be useful for you. It does pivot tables and supports spatial operators like area calculations. I've written up a short user guide since it's not totally intuitive: http://anitagraser.com/2013/02/02/group-stats-tutorial/

• The window you show would be helpful because it looks like you could add the same field more than once with multiple filters but it doesn't look the same in the latest GroupStats plugin. Are we limited to just a single field now? i.imgur.com/OUyMJIn.png Commented Jul 9, 2013 at 21:36

Thanks for all the answers. So calculating worked fine with the field calculator and the GroupStats plugin!
My results are quite strange though...the calculated area is i.e. 5.11818143422715e-08 So what can I do to get results in square meters? My projection is EPSG:3857 (WGS 84 / Pseudo Mercator)

So the link to my attribute table is here because I can't upload it here unless I got 10 reputations...! https://www.dropbox.com/s/br6hqhtcpubq06g/Attribute%20Table%20QGIS.png

Thank you all!

• Can anyone please explain me how I can convert these numbers to square meters? Thank you Commented Jul 22, 2013 at 7:35