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.
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.
Return the strack trace for any exception that may of occurred while running.
Main function for hazard impact calculation thread. Requires three properties to be set before execution can take place:
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()
This module forms part of the InaSAFE tool.