Module: is_safe_interface

This page contains the documentation for the InaSAFE is_safe_interface module.

InaSAFE Disaster risk assessment tool developed by AusAid - IS Safe Interface.

The purpose of the module is to centralise interactions between the gui package and the underlying InaSAFE packages. This should be the only place where SAFE modules are imported directly.

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.

gui.is_safe_interface.availableFunctions(theKeywordList=None)[source]

Query the inasafe engine to see what plugins are available.

Args:

theKeywordList - an optional parameter which should contain a list of 2 dictionaries (the number of items in the list is not enforced). The dictionaries should be obtained by using readKeywordsFromFile e.g.:

myFile1 = foo.shp
myFile2 = bar.asc
myKeywords1 = readKeywordsFromFile(myFile1)
myKeywords2 = readKeywordsFromFile(myFile2)
myList = [myKeywords1, myKeywords2]
myFunctions = availableFunctions(myList)
Returns:

A dictionary of strings where each is a plugin name.

Note

If theKeywordList is not provided, all available plugins will be returned in the list.

Raises:
NoFunctionsFoundException if no functions are found.
gui.is_safe_interface.calculateSafeImpact(theLayers, theFunction)[source]

Thin wrapper around the safe calculate_impact function.

Args:
  • theLayers - a list of layers to be used. They should be ordered with hazard layer first and exposure layer second.
  • theFunction - SAFE impact function instance to be used
Returns:
A safe impact function is returned
Raises:
Any exceptions are propogated
gui.is_safe_interface.getBufferedExtent(theGeoExtent, theCellSize)[source]

Grow bounding box with one unit of resolution in each direction.

Args:

  • theGeoExtent - Bounding box with format [W, S, E, N]
  • theCellSize - (resx, resy) Raster resolution in each direction.

If resolution is None bbox is returned unchanged.

Returns:
Adjusted bounding box

Raises:

Any exceptions are propogated
Note: See docstring for underlying function buffered_bounding_box
for more details.
gui.is_safe_interface.getFunctionTitle(theFunction)

Thin wrapper around the safe get_function_title.

Args:
  • theFunction - SAFE impact function instance to be used
Returns:
The title of a safe impact function is returned
Raises:
Any exceptions are propogated
gui.is_safe_interface.getOptimalExtent(theHazardGeoExtent, theExposureGeoExtent, theViewportGeoExtent)[source]

A helper function to determine what the optimal extent is. 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.

This is just a thin wrapper around safe_api.bbox_intersection.

Typically the result of this function will be used to clip input layers to a commone extent before processing.

Args:

  • theHazardGeoExtent - an array representing the hazard layer

    extents in the form [xmin, ymin, xmax, ymax]. It is assumed that the coordinates are in EPSG:4326 although currently no checks are made to enforce this.

  • theExposureGeoExtent - an array representing the exposure layer

    extents in the form [xmin, ymin, xmax, ymax]. It is assumed that the coordinates are in EPSG:4326 although currently no checks are made to enforce this.

  • theViewPortGeoExtent - an array representing the viewport

    extents in the form [xmin, ymin, xmax, ymax]. It is assumed that the coordinates are in EPSG:4326 although currently no checks are made to enforce this.

..note:: We do minimal checking as the inasafe library takes
care of it for us.
Returns:

An array containing an extent in the form [xmin, ymin, xmax, ymax] e.g.:

[100.03, -1.14, 100.81, -0.73]
Raises:
Any exceptions raised by the InaSAFE library will be propogated.
gui.is_safe_interface.getSafeImpactFunctions(theFunction=None)[source]

Thin wrapper around the safe impact_functions function.

Args:
theFunction - optional str giving a specific plugins name that should be fetched.
Returns:
A safe impact function is returned
Raises:
Any exceptions are propogated
gui.is_safe_interface.getStyleInfo(theLayer)[source]

Get styleinfo associated with a layer.

Args:

  • theLayer - InaSAFE layer (raster or vector)
Returns:
A list of dictionaries containing styleinfo info for a layer.

Raises:

  • StyleInfoNotFoundException if the style is not found.
  • InvalidParameterException if the paramers are not correct.
gui.is_safe_interface.makeAscii(x)[source]

Convert QgsString to ASCII

gui.is_safe_interface.readKeywordsFromFile(theLayerPath, theKeyword=None)[source]

Get metadata from the keywords file associated with a local file in the file system.

Note

Requires a str representing a file path instance as parameter As opposed to readKeywordsFromLayer which takes a inasafe file object as parameter.

See also

readKeywordsFromLayer

Args:

  • theLayerPath - a string representing a path to a layer

    (e.g. ‘/tmp/foo.shp’, ‘/tmp/foo.tif’)

  • theKeyword - optional - the metadata keyword to retrieve e.g. ‘title’

Returns:
A string containing the retrieved value for the keyword if the keyword argument is specified, otherwise the complete keywords dictionary is returned.
Raises:
KeywordNotFoundException if the keyword is not recognised.
gui.is_safe_interface.readKeywordsFromLayer(theLayer, keyword)[source]

Get metadata from the keywords file associated with a layer.

Note

Requires a inasafe layer instance as parameter.

See also

getKeywordFromPath

Args:

  • theLayer - a InaSAFE layer (vector or raster)
  • keyword - the metadata keyword to retrieve e.g. ‘title’
Returns:
A string containing the retrieved value for the keyword.
Raises:
KeywordNotFoundException if the keyword is not recognised.
gui.is_safe_interface.readSafeLayer(thePath)[source]

Thin wrapper around the safe read_layer function.

Args:
thePath - str representing path to layer that must be opened.
Returns:
A safe readSafeLayer object is returned.
Raises:
Any exceptions are propogated
gui.is_safe_interface.tr(theText)[source]

We define a tr() alias here since the is_safe_interface implementation below is not a class and does not inherit from QObject.

Args:
theText - string to be translated
Returns:
Translated version of the given string if available, otherwise the original string.
gui.is_safe_interface.verify(theStatement, theMessage=None)[source]

This is just a thin wrapper around safe_api.verify.

Args:
  • theStatement - expression to verify
  • theMessage - message to display on failure
Returns:
None
Raises:
VerificationError
gui.is_safe_interface.writeKeywordsToFile(theFilename, theKeywords)[source]

Thin wrapper around the safe write_keywords function.

Args:
  • thePath - str representing path to layer that must be written. If the file does not end in .keywords, its extension will be stripped off and the basename + .keywords will be used as the file.
  • theKeywords - a dictionary of keywords to be written
Returns:
A safe readSafeLayer object is returned.
Raises:
Any exceptions are propogated

Previous topic

Module: is_exceptions

Next topic

Module: is_keyword_io

This Page