[GIS] QGIS Print Composer: How to get the sum of the canopy areas that are displayed on the map

cartographyprint-composerqgis

I've already asked this question, but I didn't really get the answer I was expecting.
I will then try to reformulate with added details:
I am in the process of migrating an entire orchard mapping project from Manifold to QGIS.
Manifold has been scripted (using VB) in a way that at the bottom of each map it has generated, it will calculate and display the total canopy area of the orchard with a breakdown per variety (see image below).

enter image description here

I want to replicate this with QGIS.

From my understanding, there are 3 fields in the attributes table of my polygon shapefile layer that could be useful:

  • KPIN: every orchard has his own KPIN number. An orchard is subdivided by blocks and each block that grows a different variety of fruit will have the same KPIN number as the orchard where it belongs.
  • Canopy area: this field will calculate (with the $area expression) the surface area of our blocks (polygons).
  • Variety: this field defines what variety is being grown within our blocks

I believe there should be an expression that could use the KPIN number to pull data from the attribute tables and get what I would like to achieve:

  • the total sum of the canopy area for my KPIN (orchard)
  • a breakdown of the canopy areas per variety that is grown within the orchard

What this expression would look like?
And where should I insert my expression? Is it in the print composer, in a label?

Best Answer

You could add a table in the print composer. You can change the attributes of the table by adding and additional one with a custom expression of the type 'aggregate'. In your example you coud use 'sum(expression, group_by, filter)'

sum("Canopy area", "KPIN")

Should give you the Canopy area per KPIN

Then select to remove duplicates from the table (and make sure to remove columns that would make the rows unique) you should get a list of KPIN and their area (from the new column).

Related Question