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 logging handler that will log messages to the QGIS logging console.
A helper to add a handler to a logger, ensuring there are no duplicates.
theLogger: logging.logger instance
added if an instance of that Handler subclass already exists.
returns a dictionary of defaults values to be used it takes the DEFAULTS from safe and modifies them according to qgis
QSettings
Convert exception into a string and and stack trace
iterates over self.layer and returns all the attribute names of attributes that have int or string as field type and the position
of the theCurrentKeyword in the attribute names list
acceptable for the attribute. e.g.: [QtCore.QVariant.Int, QtCore.QVariant.String]
theCurrentKeyword - the currently stored keyword for the attribute
field type
this is None if theCurrentKeyword is not in the lis of attributes
Return resolution of raster layer in EPSG:4326
If input layer is already in EPSG:4326, simply return the resolution If not, work it out based on EPSG:4326 representations of its extent
Get a standard html footer for wrapping content in.
Utility function to humanise seconds value into e.g. 10 seconds ago.
The function will try to make a nice phrase of the seconds count provided.
Note
Currently theSeconds that amount to days are not supported.
Make a little table for attribution of data sources used in impact.
theKeywords: dict{} - a keywords dict for an impact layer.
text in the attribution output. Defaults to False.
tell if a qgis theLayer is vectorial and d its geometries polygons Args:
the theLayer
Convert measurement in points to one in mm.
Convert measurement in points to one in mm.
Get the version of QGIS Args:
None
Set QGIS raster style based on InaSAFE style dictionary.
This function will set both the colour map and the transparency for the passed in layer.
Set QGIS vector style based on InaSAFE style dictionary.
For opaque a value of 0 can be used. For fully transparent, a value of 100 can be used. The function should take care to scale the transparency level to between 0 and 100.
Example:
{‘target_field’: ‘DMGLEVEL’, ‘style_classes’: [{‘transparency’: 1, ‘max’: 1.5, ‘colour’: ‘#fecc5c’,
‘min’: 0.5, ‘label’: ‘Low damage’, ‘size’ : 1},
- {‘transparency’: 55, ‘max’: 2.5, ‘colour’: ‘#fd8d3c’,
- ‘min’: 1.5, ‘label’: ‘Medium damage’, ‘size’ : 1},
- {‘transparency’: 80, ‘max’: 3.5, ‘colour’: ‘#f31a1c’,
- ‘min’: 2.5, ‘label’: ‘High damage’, ‘size’ : 1}]}
Note
The transparency and size keys are optional. Size applies to points only.
Run once when the module is loaded and enable logging
Args: None
Returns: None
Raises: None
Borrowed heavily from this: http://docs.python.org/howto/logging-cookbook.html
Use this to first initialise the logger (see safe/__init__.py):
from safe_qgis import utilities
utilities.setupLogger()
You would typically only need to do the above once ever as the safe modle is initialised early and will set up the logger globally so it is available to all packages / subpackages as shown below.
In a module that wants to do logging then use this example as a guide to get the initialised logger instance:
# The LOGGER is intialised in utilities.py by init
import logging
LOGGER = logging.getLogger('InaSAFE')
Now to log a message do:
LOGGER.debug('Some debug message')
Note
The file logs are written to the inasafe user tmp dir e.g.: /tmp/inasafe/23-08-2012/timlinux/logs/inasafe.log
Create a QPrinter instance defaulted to print to an A4 portrait pdf
We define a tr() alias here since the utilities 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
This module forms part of the InaSAFE tool.