“In this module we will introduce creating template overrides in InaSAFE”
When InaSAFE generates a report, it uses a system of 'overrides' to determine which template should be used to produce the map report. By creating your own template and saving it with a specific name (in the format hazard-exposure.qpt
- e.g. flood-population.qpt
), which InaSAFE will detect and offer as an alternative report template. These are known as template overrides and provide a powerful way for you to customise the outputs from InaSAFE.
The overrides only alter the map report - other standard reporting products are still generated as usual and are not customisable without coding. When you press the print button in InaSAFE, the print dialog will offer you the option of using an override template if one is found. You can also select a specific template if you prefer. Templates the InaSAFE installation directory (~/.qgis2/python/plugins/inasafe/safe/resources/qgis-composer-templates/
and from your ~/.qgis2/inasafe
folder are automatically listed in the ‘specific template from search directories’ combo box. Lastly, you can choose a template from anywhere on the file system if you prefer.
The template itself is a QGIS Map Composer template, saved as a ‘.qpt’ file which you do from within map composer. To develop the template, the normal workflow is to run a sample analysis for the hazard / exposure template that you are interested in and then to either open the standard map template in composer from within the InaSAFE print dialog, or to start a blank template whilst the analysis results layer is active in QGIS.
InaSAFE provides a number of expressions and variables that can be used in your map composer project to produce your report.
Goal: To create an override template for population affected by flood
In this exercise, we will generate a custom report which will show some simple numeric results for a flood on population scenario.
Experiment with further customisation of your report by adding a third page which includes outputs from other InaSAFE expressions.
Name | Expectation |
---|---|
Input layers |
tandale_floods, wards, worldpop_25 |
Analysis question |
In the event of Floods, how many People will be affected? Summarise the results by Wards. |
Print options (report development) |
Uncheck all InaSAFE reports, select the standard landscape and portrait maps template under map reports |
Print destination |
Open in layout designer |
Print composer number of pages |
2 |
HTML Frame Expression |
[% analysis_summary_report() %] |
Save template filename |
~/.qgis2/inasafe/flood-population.qpt |
Print options (report preview) |
Uncheck all InaSAFE reports, select the override template |
Print destination (report preview) |
Open as PDF |
The customisation process works the same way for all hazards and exposures but the available expressions may vary. For example, when carrying out an analysis of flood on structures, population-related fields in the impact summary table will not be accessible. The InaSAFE manual includes a list of all the expressions that are provided and what they do.
If you want to make your composer templates available to other colleagues in your organisation, you should bare a few things in mind:
<img>
tag).inasafe_logo_black_path()
Is. flood-hazard.qpt a valid template override name?:
Why do some expressions include the characters [% and %}?:
Download the sample data for the lesson.