3

Assuming I have a basic shapefile with the following columns: name, use, acres

I would like to generate a more visually appealing dynamic table in layout view:

Use         Name    Acres

Building
                Bld A    0.2
                Bld B    0.3
      total                0.5

Parkinhg
                North    0.3
                East      0.5
                South    0.2
                West     0.1
      total                1.1

I've looked around the print composer and found the attribute table, but I can't seem to add sum to the end of each use. I've also explored the GroupStats plugin, but am having a hard time.

I am wondering if I need to learn Python, or something similar, to get the desired results?

1

To add the sum you could create a virtual layer with the following code :

SELECT SUM("acres") as 'Sum' FROM "YourShapefileName" 

You will get a one row table (plus header) that you can then insert in your composer.

If you want to have multiple sum for different categories just add a WHERE close at the end, for exemple :

SELECT SUM("acres") as 'Sum', "use" FROM "YourShapefileName" WHERE "use"='Building'

with this you get the sum for all building.

To get your layout looking as in your exemple you will need to add several time the original table (one for each use) and format them to your liking then add the corresponding virtual layer at the bottom.

This is not an optimal solution because if the number of row change you will have to move the sum tables to keep them at the bottom...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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