### Navigation

- index
- modules
- next
- previous
- Home »
- Contents »
- InaSAFE’s API documentation »
- Package::safe_qgis »

# Module: safe_qgis.safe_interface

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.

`safe_qgis.safe_interface.``availableFunctions`(theKeywordList=None)

  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.

`safe_qgis.safe_interface.``calculateSafeImpact`(theLayers, theFunction)

  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

`safe_qgis.safe_interface.``getBufferedExtent`(theGeoExtent, theCellSize)

  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.

`safe_qgis.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

`safe_qgis.safe_interface.``getOptimalExtent`(theHazardGeoExtent, theExposureGeoExtent, theViewportGeoExtent=None)

  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 (optional) - 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.

`safe_qgis.safe_interface.``getSafeImpactFunctions`(theFunction=None)

  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

`safe_qgis.safe_interface.``getStyleInfo`(theLayer)

  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.

`safe_qgis.safe_interface.``makeAscii`(x)

  Convert QgsString to ASCII

`safe_qgis.safe_interface.``readKeywordsFromFile`(theLayerPath, theKeyword=None)

  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.

`safe_qgis.safe_interface.``readKeywordsFromLayer`(theLayer, keyword)

  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.

`safe_qgis.safe_interface.``readSafeLayer`(thePath)

  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

`safe_qgis.safe_interface.``tr`(theText)

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

  Note

  see http://tinyurl.com/pyqt-differences

  Args:
    theText - string to be translated
  Returns:
    Translated version of the given string if available, otherwise the original string.

`safe_qgis.safe_interface.``verify`(theStatement, theMessage=None)

  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

`safe_qgis.safe_interface.``writeKeywordsToFile`(theFilename, theKeywords)

  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:
    None
  Raises:
    Any exceptions are propogated

This module forms part of the InaSAFE tool.

### Navigation

- index
- modules
- next
- previous
- Home »
- Contents »
- InaSAFE’s API documentation »
- Package::safe_qgis »