Module: safe_qgis.dock

InaSAFE Disaster risk assessment tool developed by AusAid - GUI 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.

Todo

Check raster is single band

class safe_qgis.dock.Dock(iface)[source]

Dock implementation class for the inaSAFE plugin.

accept()[source]

Execute analysis when run button is clicked.

Todo

FIXME (Tim) We may have to implement some polling logic because the button click accept() function and the updating of the web view after model completion are asynchronous (when threading mode is enabled especially)

acceptCancelled(theOldKeywords)[source]

Deal with user cancelling post processing option dialog.

Args:
theOldKeywords: dict - keywords dictionary to reinstate.
Returns:
None
Raises:
None
canvasLayersetChanged()[source]

A helper slot to update dock combos if canvas layerset changes.

Activated when the layerset has been changed (e.g. one or more layer visibilities changed). If self.showOnlyVisibleLayersFlag is set to False this method will simply return, doing nothing.

Args:
None
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
checkMemoryUsage()[source]

Slot to check if analysis is feasible when extents change.

For simplicity, we will do all our calcs in geocrs.

Args:
None
Returns:
str: A string containing notes about how much memory is needed
for a single raster and if this is likely to result in an error.

Note

The dock is also updated with a message indicating if the memory usage is likely to be too much for the current system.

completed()[source]

Slot activated when the process is done.

connectLayerListener()[source]

Establish a signal/slot to listen for changes in the layers loaded in QGIS.

..seealso:: disconnectLayerListener

Args:
None
Returns:
None
Raises:
None
disableBusyCursor()[source]

Disable the hourglass cursor

disconnectLayerListener()[source]

Destroy the signal/slot to listen for changes in the layers loaded in QGIS.

..seealso:: connectLayerListener

Args:
None
Returns:
None
Raises:
None
displayHtml(theMessage)[source]

Apply header and footer to html snippet and display in wvResults.

Args:
theMessage: An html snippet. Do not include head and body elements.
Returns:
None
Raises:
None
enableBusyCursor()[source]

Set the hourglass enabled.

extentToGeoArray(theExtent, theSourceCrs)[source]

Convert the supplied extent to geographic and return as an array.

Args:
  • theExtent: QgsRectangle defining a spatial extent in any CRS
  • theSourceCrs: QgsCoordinateReferenceSystem for theExtent.
Returns:
list: a list in the form [xmin, ymin, xmax, ymax] where all
coordinates provided are in Geographic / EPSG:4326.
Raises:
None
getClipParameters()[source]

Calculate the best extents to use for the assessment.

Args:
None
Returns:
  • myExtraExposureKeywords: dict - any additional keywords that

    should be written to the exposure layer. For example if rescaling is required for a raster, the original resolution can be added to the keywords file.

  • myBufferedGeoExtent: list - [xmin, ymin, xmax, ymax] - the best

    extent that can be used given the input datasets and the current viewport extents.

  • myCellSize: float - the cell size that is the best of the

    hazard and exposure rasters.

  • myExposureLayer: QgsMapLayer - layer representing exposure.

  • myGeoExtent: list - [xmin, ymin, xmax, ymax] - the unbuffered

    intersection of the two input layers extents and the viewport.

  • myHazardLayer: QgsMapLayer - layer representing hazard.

Raises:
InsufficientOverlapError
getExposureLayer()[source]

Get the QgsMapLayer currently selected in the exposure combo.

Obtain QgsMapLayer id from the userrole of the QtCombo for exposure and return it as a QgsMapLayer.

Args:
None
Returns:
QgsMapLayer - currently selected map layer in the exposure combo.
Raises:
None
getFunctionID(theIndex=None)[source]

Get the canonical impact function ID for the currently selected function (or the specified combo entry if theIndex is supplied. Args:

theIndex int - Optional index position in the combo that you
want the function id for. Defaults to None. If not set / None the currently selected combo item’s function id will be returned.
Returns:
myFunctionID str - String that identifies the function
Raises:
None
getFunctions()[source]

Obtain a list of impact functions from the impact calculator.

Args:
None.
Returns:
None
Raises:
no
getHazardLayer()[source]

Get the QgsMapLayer currently selected in the hazard combo.

Obtain QgsMapLayer id from the userrole of the QtCombo for hazard and return it as a QgsMapLayer.

Args:
None
Returns:
QgsMapLayer - currently selected map layer in the hazard combo.
Raises:
None
getLayers()[source]

Helper function to obtain a list of layers currently loaded in QGIS.

On invocation, this method will populate cboHazard, cboExposure and cboAggregate on the dialog with a list of available layers. Only singleband raster layers will be added to the hazard layer list,only point vector layers will be added to the exposure layer list and Only polygon vector layers will be added to the aggregate list

Args:
None.
Returns:
None
Raises:
no
getPostProcessingLayer()[source]

Get the QgsMapLayer currently selected in the post processing combo.

Obtain QgsMapLayer id from the userrole of the QtCombo for post processing combo return it as a QgsMapLayer.

Args:
None
Returns:
  • None if no aggregation is selected or cboAggregation is

    disabled, otherwise:

  • QgsMapLayer - a polygon layer.

Raises:
None
hideBusy()[source]

A helper function to indicate processing is done.

htmlFooter()[source]

Get a standard html footer for wrapping content in.

htmlHeader()[source]

Get a standard html header for wrapping content in.

initializePostProcessor()[source]

Initializes and clears self._postProcessingOutput.

Note

Needs to run at the end of postProcess.

Args: None Returns: None

layerChanged(theLayer)[source]

Handler for when the QGIS active layer is changed. If the active layer is changed and it has keywords and a report, show the report..

Args:
theLayer - the QgsMapLayer instance that is now active..
Returns:
None.
Raises:
no exceptions explicitly raised.
layerWasAdded()[source]

QGIS <= 1.7.x slot to notify us when a layer was added.

Slot for the old (pre QGIS 1.8 api) to notify us when a layer is added. This is suboptimal since if many layers are added this slot gets called multiple times. This slot simply delegates to getLayers and is only implemented here to make the connections between the different signals and slots clearer and better documented.

..note :: see layersAdded() - this slot will be deprecated
eventually.
layerWillBeRemoved()[source]

Slot for the old (pre QGIS 1.8 api) to notify us when a layer is removed. This is suboptimal since if many layers are removed this slot gets called multiple times. This slot simply delegates to getLayers and is only implemented here to make the connections between the different signals and slots clearer and better documented.

layersAdded(theLayers=None)[source]

QGIS 1.8+ slot to notify us when a group of layers are added.

Slot for the new (QGIS 1.8 and beyond api) to notify us when a group of layers is are added. This is optimal since if many layers are added this slot gets called only once. This slot simply delegates to getLayers and is only implemented here to make the connections between the different signals and slots clearer and better documented.

Note

Requires QGIS 1.8 and better api.

layersWillBeRemoved()[source]

QGIS 1.8+ slot to notify us when a group of layers are removed. This is optimal since if many layers are removed this slot gets called only once. This slot simply delegates to getLayers and is only implemented here to make the connections between the different signals and slots clearer and better documented.

Note

Requires QGIS 1.8 and better api.

on_cboExposure_currentIndexChanged(theIndex)[source]

Automatic slot executed when the Exposure combo is changed.

This is here so that we can see if the ok button should be enabled.

Note

Don’t use the @pyqtSlot() decorator for autoslots!

Args:
None.
Returns:
None.
Raises:
No exceptions explicitly raised.
on_cboFunction_currentIndexChanged(theIndex)[source]

Automatic slot executed when the Function combo is changed.

This is here so that we can see if the ok button should be enabled.

Args:
None.
Returns:
None.
Raises:
no exceptions explicitly raised.
on_cboHazard_currentIndexChanged(theIndex)[source]

Automatic slot executed when the Hazard combo is changed.

This is here so that we can see if the ok button should be enabled.

Note

Don’t use the @pyqtSlot() decorator for autoslots!

Args:
None.
Returns:
None.
Raises:
No exceptions explicitly raised.
on_toolFunctionOptions_clicked()[source]

Automatic slot executed when toolFunctionOptions is clicked.

Args:
None.
Returns:
None.
Raises:
no exceptions explicitly raised.
optimalClip()[source]

A helper function to perform an optimal clip of the input data. Optimal extent should be considered as the intersection between the three inputs. The inasafe library will perform various checks to ensure that the extent is tenable, includes data from both etc.

The result of this function will be two layers which are clipped and resampled if needed, and in the EPSG:4326 geographic coordinate reference system.

Args:
None
Returns:
A two-tuple containing the paths to the clipped hazard and exposure layers.
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
postProcess()[source]

Run all post processing steps.

Called on self.runner SIGNAL(‘done()’) starts all postprocessing steps

Args:
None
Returns:
None
postProcessingTables()[source]

Parses the postprocessing output as one table per postprocessor.

Args:
None
Returns:
str - a string containing the html
preparePolygonLayerForAggr(theLayerFilename, theQgisLayer)

A helper function to align the polygons to the postprocLayer polygons. If one input polygon is in two or more postprocLayer polygons then it is divided so that each part is within only one of the postprocLayer polygons. this allows to aggregate in postrocessing using centroid in polygon.

The function assumes EPSG:4326 but no checks are enforced

Args:
theLayerFilename str of the file to be processed
Returns:
str of the processed file
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
printMap()[source]

Slot to print map when print map button pressed.

Args:
None
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
readImpactLayer(myEngineImpactLayer)[source]

Helper function to read and validate layer.

Args
myEngineImpactLayer: Layer object as provided by InaSAFE engine.
Returns
validated QGIS layer or None
Raises
Exception if layer is not valid
readSettings()[source]

Set the dock state from QSettings. Do this on init and after changing options in the options dialog.

Args:
None
Returns:
None
Raises:
None
restoreFunctionState(theOriginalFunction)[source]

Restore the function combo to a known state.

Args:
theOriginalFunction - name of function that should be selected
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
restoreState()[source]

Restore the state of the dock to the last known state.

Args:
None
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
run()[source]

Execute analysis when ok button on settings is clicked.

saveState()[source]

Save the current state of the ui to an internal class member so that it can be restored again easily.

Args:
None
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propagated.
setFunctionOptionsStatus()[source]

Helper function to toggle the tool function button based on context.

If there are function parameters to configure then enable it, otherwise disable it.

Args:
None.
Returns:
None.
Raises:
no exceptions explicitly raised.
setOkButtonStatus()[source]

Helper function to set the ok button status based on form validity.

Args:
None.
Returns:
None.
Raises:
no exceptions explicitly raised.
setupCalculator()[source]

Initialise ImpactCalculator based on the current state of the ui.

Args:
None
Returns:
None
Raises:
Propagates any error from :func:optimalClip()
showBusy(theTitle=None, theMessage=None, theProgress=0)[source]

A helper function to indicate the plugin is processing.

Args:
  • theTitle - an optional title for the status update. Should be plain text only
  • theMessage - an optional message to pass to the busy indicator. Can be an html snippet.
  • theProgress - a number between 0 and 100 indicating % complete
Returns:
None
Raises:
Any exceptions raised by the InaSAFE library will be propagated.

..note:: Uses bootstrap css for progress bar.

showHelp()[source]

Load the help text into the wvResults widget

spawnError(theException, theMessage)

A helper to spawn an error and halt processing.

An exception will be logged, busy status removed and a message displayed.

Args:
  • theException: Exception - an exception that was raised.
  • theMessage: str - a string to display.
Raises:
None
Exception:
None
toggleAggregationCombo()[source]

Helper function to toggle the aggregation combo enabled status.

Whether the combo is toggled on or off will depend on the current dock status.

Args:
None.
Returns:
None
Raises:
no
validate()[source]

Helper method to evaluate the current state of the dialog and determine if it is appropriate for the OK button to be enabled or not.

Note

The enabled state of the OK button on the dialog will NOT be updated (set True or False) depending on the outcome of the UI readiness tests performed - only True or False will be returned by the function.

Args:
None.
Returns:

A two-tuple consisting of:

  • Boolean reflecting the results of the valudation tests.
  • A message indicating any reason why the validation may have failed.

Example:

flag,myMessage = self.validate()
Raises:
no exceptions explicitly raised
viewportGeoArray()[source]

Obtain the map canvas current extent in EPSG:4326.

Args:
  • theExtent: QgsRectangle defining a spatial extent in any CRS
  • theSourceCrs: QgsCoordinateReferenceSystem for theExtent.
Returns:
list: a list in the form [xmin, ymin, xmax, ymax] where all
coordinates provided are in Geographic / EPSG:4326.
Raises:
None

Note

Delegates to self.extentToGeoArray()

This module forms part of the InaSAFE tool.

Previous topic

Module: safe_qgis.html_renderer

Next topic

Module: safe_qgis.keyword_io

This Page