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.
Convert exception into a string and and stack trace
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.
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.
theQgsRasterLayer: Qgis layer style: Dictionary of the form as in the example below style_classes = [dict(colour=’#38A800’, quantity=2, transparency=0),
dict(colour=’#38A800’, quantity=5, transparency=1), dict(colour=’#79C900’, quantity=10, transparency=1), dict(colour=’#CEED00’, quantity=20, transparency=1), dict(colour=’#FFCC00’, quantity=50, transparency=1), dict(colour=’#FF6600’, quantity=100, transparency=1), dict(colour=’#FF0000’, quantity=200, transparency=1), dict(colour=’#7A0000’, quantity=300, transparency=1)]
Set QGIS vector style based on InaSAFE style dictionary
theQgisVectorLayer: Qgis layer theStyle: Dictionary of the form as in the example below
{‘target_field’: ‘DMGLEVEL’, ‘style_classes’: [{‘opacity’: 1, ‘max’: 1.5, ‘colour’: ‘#fecc5c’,
‘min’: 0.5, ‘label’: ‘Low 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.