safe.gui.tools.impact_merge_dialog module

Impact Layer Merge Dialog.

Contact : ole.moller.nielsen@gmail.com

Note

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

class safe.gui.tools.impact_merge_dialog.ImpactMergeDialog(parent=None, iface=None)[source]

Bases: PyQt4.QtGui.QDialog, Ui_ImpactMergeDialogBase

Tools for merging 2 impact layer based on different exposure.

accept()[source]

Do merging two impact layers.

generate_html_reports(first_report_dict, second_report_dict)[source]

Generate html file for each aggregation units.

It also saves the path of the each aggregation unit in self.html_reports.

Ex. {"jakarta barat": "/home/jakarta barat.html",
     "jakarta timur": "/home/jakarta timur.html"}
Parameters:
  • first_report_dict (dict) – Dictionary report from first impact.
  • second_report_dict (dict) – Dictionary report from second impact.
static generate_report_dictionary_from_dom(html_dom)[source]

Generate dictionary representing report from html dom.

Parameters:html_dom (str) – Input representing document dom as report from each impact layer report.
Returns:Dictionary representing html_dom.
Return type:dict

Dictionary Structure:

{ Aggregation_Area:
    {Exposure Type:{
        Exposure Detail}
    }
}

Example:

{"Jakarta Barat":
    {"Closed buildings":
        {"Total inundated":150,
         "Places of Worship": "No data"
        }
    }
}
generate_report_summary(first_report_dict, second_report_dict)[source]

Generate report summary for each aggregation area from merged report dictionary.

For each exposure, search for the total only. Report dictionary looks like this:

Parameters:
  • first_report_dict (dict) – Dictionary report from the first impact.
  • second_report_dict (dict) – Dictionary report from the second impact.

Dictionary structure:

{ aggregation_area:
    {exposure_type:{
       exposure_detail}
    }
}

Example:

{"Jakarta Barat":
    {"Closed buildings":
        {"Total inundated":150,
         "Places of Worship": "No data"
        }
    }
}
generate_reports()[source]

Generate PDF reports for each aggregation unit using map composer.

First the report template is loaded with the renderer from two impact layers. After it’s loaded, if it is not aggregated then we just use composition to produce report. Since there are two impact maps here, we need to set a new extent for these impact maps by a simple calculation.

If it is not aggregated then we use a powerful QGIS atlas generation on composition. Since we save each report table representing each aggregated area on self.html_report (which is a dictionary with the aggregation area name as a key and its path as a value), and we set the aggregation area name as current filename on atlas generation, we can match these two so that we have the right report table for each report.

For those two cases, we use the same template. The report table is basically an HTML frame. Of course after the merging process is done, we delete each report table on self.html_reports physically on disk.

get_project_layers()[source]

Get impact layers and aggregation layer currently loaded in QGIS.

help_toggled(flag)[source]

Show or hide the help tab in the stacked widget.

Parameters:flag (bool) – Flag indicating whether help should be shown or hidden.
hide_help()[source]

Hide the usage info from the user.

load_template(map_settings)[source]

Load composer template for merged report.

Validate it as well. The template needs to have: 1. QgsComposerMap with id ‘impact-map’ for merged impact map. 2. QgsComposerPicture with id ‘safe-logo’ for InaSAFE logo. 3. QgsComposerLabel with id ‘summary-report’ for a summary of two impacts. 4. QgsComposerLabel with id ‘aggregation-area’ to indicate the area of aggregation. 5. QgsComposerScaleBar with id ‘map-scale’ for impact map scale. 6. QgsComposerLegend with id ‘map-legend’ for impact map legend. 7. QgsComposerPicture with id ‘organisation-logo’ for organisation logo. 8. QgsComposerLegend with id ‘impact-legend’ for map legend. 9. QgsComposerHTML with id ‘merged-report-table’ for the merged report.

Parameters:map_settings (QgsMapSettings, QgsMapRenderer) – Map settings.
merge()[source]

Merge the postprocessing_report from each impact.

on_directory_chooser_clicked()[source]

Show a dialog to choose directory.

on_report_template_chooser_clicked()[source]

Show a dialog to choose directory

prepare_input()[source]

Fetch all the input from dialog, validate, and store it.

Consider this as a bridge between dialog interface and our logical stored data in this class

Raises:InvalidLayerError, CanceledImportDialogError
read_settings()[source]

Set some variables from global settings on inasafe options dialog.

require_directory()[source]

Ensure directory path entered in dialog exist.

When the path does not exist, this function will ask the user if he wants to create it or not.

Raises:CanceledImportDialogError - when user chooses ‘No’ in the question dialog for creating directory, or ‘Yes’ but the output directory path is empty
restore_state()[source]

Read last state of GUI from configuration file.

save_state()[source]

Store current state of GUI to configuration file

show_help()[source]

Show usage info to the user.

validate_all_layers()[source]

Validate all layers based on the keywords.

When we do the validation, we also fetch the information we need:

  1. ‘map_title’ from each impact layer
  2. ‘exposure_title’ from each impact layer
  3. ‘postprocessing_report’ from each impact layer
  4. ‘aggregation_attribute’ on aggregation layer, if user runs merging tools with aggregation layer chosen

The things that we validate are:

  1. ‘map_title’ keyword must exist on each impact layer
  2. ‘exposure_title’ keyword must exist on each impact layer
  3. ‘postprocessing_report’ keyword must exist on each impact layer
  4. ‘hazard_title’ keyword must exist on each impact layer. Hazard title from first impact layer must be the same with second impact layer to indicate that both are generated from the same hazard layer.
  5. ‘aggregation attribute’ must exist when user wants to run merging tools with aggregation layer chosen.