Generate an automatic report with QGIS and Data Plotly: integrate graphics into a PDF atlas

Having seen how to create and export a series of graphs with Data Plotly, let’s move on to the next step: integrating these graphs into a QGIS atlas or automated report. This method can be used to produce customized PDF reports or thematic sheets, one per range, commune, site or entity.



Objective

  • Create a dynamic PDF report by entity (e.g.: one sheet per beach);
  • Insert graphs generated with Data Plotly into each atlas page;
  • Use QGIS Atlas functions and a little automation.


Use case example

You have a releves_dechets layer and a beaches (or communes) layer. You want to create a report for each beach, containing :

  • The name of the beach
  • A zoomed-in map of the area
  • A PNG graphic representing the waste collected (created with Data Plotly)
  • Some dynamic statistics (sum, average…)


Step 1: Prepare graphics for each range

Use the Python script described above to generate one PNG image per range:

  • graph_Anse_Mourouk.png, graph_Pointe_Coton.png, etc.
  • Make sure the image name corresponds exactly to the value of the range field in the main layer.


Step 2: Create the layout in the Layout Composer

  1. Go to Project > Layout > New layout
  2. Add :

    • A map frame (linked to the beach layer)
    • A dynamic text field (e.g.: [% “beach” %])
    • An image frame: click on the “Add image” icon

  3. Activate the Atlas :

    • Cover object = layer (e.g. beaches)
    • Sorting (optional): you can choose a field for page order (e.g. name)
    • Filter entities with an expression (optional)
    • Automatic zoom on entity

  4. Click on your main map in the layout (the map to be automatically centered)
  5. In the Object Properties panel, Atlas Attributes section, check :

    • ✅ Controlled by atlas
    • ✅ Fit to entity


Step 3: Dynamically insert PNG graphics

In the image frame, check “Image path from data”

Then enter an expression like:

'file:///C:/temp/export_graphiques/graph_' || "plage" || '.png'

This will automatically display the image corresponding to each entity.

Tip: you can use replace(“plage”, ‘ ’, ‘_’) if file names don’t have spaces.


Step 4: Export the atlas

  • Click on “Export Atlas as PDF” ;
  • Choose an output folder;
  • Each page will contain: the map, the beach name, the graph, and associated info.


Bonus: add dynamic statistics

Add text fields with QGIS expressions such as :

aggregate(‘releves_dechets’, ‘sum’, “quantite”, filter := “plage” = attribute(@atlas_feature, ‘plage’))

This provides automatic totals or averages for each record.


To summarize

Step Function
Graphics generation With Data Plotly + Python
Customized layout QGIS composer
Automatic insertion Dynamic fields + path to PNG
Export multi-page PDF Atlas function


Use case ideas

  • Observation sheets by commune (fauna, flora, waste)
  • Environmental reports by site
  • Census maps + graphics
  • Site or project monitoring


Coming soon…

In the next article, we’ll go a step further and show you how to create a dynamic dashboard in QGIS itself, without leaving the GIS environment: combine Data Plotly, expressions, widgets and panels to build a real-time analysis interface.


Si cet article vous a intéressé et que vous pensez qu'il pourrait bénéficier à d'autres personnes, n'hésitez pas à le partager sur vos réseaux sociaux en utilisant les boutons ci-dessous. Votre partage est apprécié !

Leave a Reply

Your email address will not be published. Required fields are marked *