Module: safe_qgis.impact_calculator_thread

InaSAFE Disaster risk assessment tool developed by AusAid - ISImpactCalculatorThread.

The module provides a high level interface for running SAFE scenarios.

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_qgis.impact_calculator_thread.ImpactCalculatorThread(theHazardLayer, theExposureLayer, theFunction)[source]

A threaded class to compute an impact scenario. Under python a thread can only be run once, so the instances based on this class are designed to be short lived. We inherit from QObject so that we can use Qt translation self.tr calls and emit signals.

Todo

implement this class using QThread as a base class since it supports thread termination which python threading doesnt seem to do. Also see the techbase article below for emitting signals across threads using Qt.QueuedConnection. http://techbase.kde.org/Development/Tutorials/ Python_introduction_to_signals_and_slots

Users of this of this class can listen for signals indicating when processing is done. For example:

from is_impact_calculator_thread import ImpactCalculatorThread
n = ImpactCalculatorThread()
n.done.connect(n.showMessage)
n.done.emit()

Prints ‘hello’ to the console

See also

http://techbase.kde.org/Development/Tutorials/ Python_introduction_to_signals_and_slots

for an alternative (maybe nicer?) approach.

impactLayer()[source]

Return the InaSAFE layer instance which is the output from the last run.

lastException()[source]

Return any exception that may have been raised while running

lastTraceback()[source]

Return the strack trace for any exception that may of occurred while running.

result()[source]

Return the result of the last run.

run()[source]

Main function for hazard impact calculation thread. Requires three properties to be set before execution can take place:

  • Hazard layer - a path to a raster,
  • Exposure layer - a path to a vector points layer.
  • Function - a function that defines how the Hazard assessment will be computed.

After the thread is complete, you can use the filename and result accessors to determine what the result of the analysis was:

calculator = ImpactCalculator()
rasterPath = os.path.join(TESTDATA, 'xxx.asc')
vectorPath = os.path.join(TESTDATA, 'xxx.shp')
calculator.setHazardLayer(self.rasterPath)
calculator.setExposureLayer(self.vectorPath)
calculator.setFunction('Flood Building Impact Function')
myRunner = calculator.getRunner()
#wait till completion
myRunner.join()
myResult = myRunner.result()
myFilename = myRunner.filename()
Args:
None.
Returns:
None
Raises:
InsufficientParametersException set.
showMessage()[source]

For testing only

This module forms part of the InaSAFE tool.

Previous topic

Module: safe_qgis.options_dialog_base

Next topic

Module: safe_qgis.options_dialog

This Page