TransWikia.com

QGIS Reports: Create HTML table by iteration through every field in attribute table of layer

Geographic Information Systems Asked by manumanul on May 27, 2021

I have a QGIS project and I want to generate a report out of this.
I am using the report-tool (https://docs.qgis.org/3.16/en/docs/user_manual/print_composer/create_reports.html) as it suits me better than the atlases. I defined my pages via HTML documents and iterated through the corresponding QGIS layer using the field group section.

So far, so good, but now I would like to additionally add a summary table at the beginning of the report, showing 1 row per entry (in this summary table), i.e. I need to

  1. Access the values of my QGIS layer within the HTML (which works well for the field group section, but does not seem to work in a static section), and then
  2. Create a HTML expression which iterates through every entry of my QGIS layer and adds an additional line to the summary table.

Unfortunately, I am already stuck with the first challenge…

One Answer

As Erik said in comment the attribute table migth suits your needs. The styling option is limited compare to html table but very easy to do it related to your data.

In the layout, go to panel report organaizer and select your group. Then check include header and hit Edit button. It opens a new page that will be included before your group of pages.

enter image description here

In this page add an attribute table. In the item property you will have to set the layer to be the same that is used for the group in the report. (If you want to link it automaticaly with your layer selected in the group you can activate the data defined overide with the expression @atlas_layername).

Then you click the Attributes... button to choose which field will be shown or not. If you want to add a column based on computed value for every features you can add a new row defined by expression. For example round ($length / 1000,2) || 'km' to add the length of your feature in km (only if you have lines).

enter image description here

Adjust the size and styling and sorting to get the result you want. Here is the documentation for attribute table.

Then to add a summary line there is not really a dedicated solution for that. You can do the same table as before, but this table will not look for features attribute but will look on aggregation on all the layer.

First you have to copy-paste your attribute table created before. For every column you will have to edit the attribute and transform "Your_field" to be aggregate(@layer_name, 'sum', "Your_field"). Example below for field LONGUEUR in my attribute table. You may find aggregate function possibility here or in the integrated help.

enter image description here

Then you will have to set the maximum row to one in the property and may be to display no header if you have your first table above. You can refresh the view or export a report to see how it is and adjust the option to suits your needs.

Correct answer by Corentin Lemaitre on May 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP