safe.impact_statistics.aggregator module

InaSAFE Disaster risk assessment tool developed by AusAid - Aggregator.

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.

class safe.impact_statistics.aggregator.Aggregator(extent, aggregation_layer)[source]

Bases: PyQt4.QtCore.QObject

The aggregator class facilitates aggregation of impact function results.

aggregate(safe_impact_layer)[source]

Do any requested aggregation post processing.

Performs Aggregation postprocessing step by

  • creating a copy of the data set clipped by the impact layer bounding box
  • stripping all attributes beside the aggregation attribute
  • delegating to the appropriate aggregator for raster and vectors
Parameters:safe_impact_layer (read_layer) – The layer that will be aggregated.
Raises:ReadLayerError
copy_keywords(layer, out_filename)[source]

It is a wrapper around self._keyword_io.copy_keywords

Parameters:
  • layer (QgsMapLayer) – Layer you want to get the keywords for.
  • out_filename (str) – Output filename that the keywords should be written to.
Raises:

All exceptions are propagated.

deintersect()[source]

Ensure there are no intersecting features with self.layer.

This should only happen after initial checks have been made.

Note

Buildings are not split up by this method.

Raises:InsufficientParametersError if hazard_layer or exposure_layer is not set.
extent[source]

Accessor for extent property.

get_default_keyword(keyword)[source]

It is a wrapper around self._defaults. Returns default attribute keyword.

Parameters:keyword (str) – A string containing the keyword to be returned for the layer.
Returns:The value for the given key if it is present.
Return type:str
Raises:All exceptions are propagated.
get_statistics(layer)[source]

It is a wrapper around self._keyword_io.read_keywords

Parameters:layer (QgsMapLayer) – Layer you want to get the keywords for.
Returns:KeywordIO.get_statistics object
Return type:KeywordIO.get_statistics
Raises:All exceptions are propagated.
read_keywords(layer, keyword=None)[source]

It is a wrapper around self._keyword_io.read_keywords

Parameters:
  • layer (QgsMapLayer) – Layer you want to get the keywords for.
  • keyword (str) – Optional specific keyword you want the value for.
Returns:

KeywordIO.read_keywords object

Return type:

KeywordIO.read_keywords

Raises:

All exceptions are propagated.

run_processing_algorithm(algorithm_name, *args)[source]

Adapt from processing.runalg with our own Processing.

Parameters:
  • algorithm_name (str) – The name of the algorithm.
  • args (list) – list of arguments
Returns:

The ouput of the algorithm.

Return type:

dict

set_layers(hazard_layer, exposure_layer)[source]

Set up aggregator layers

Parameters:
  • hazard_layer (QgsMapLayer) – A hazard layer.
  • exposure_layer (QgsMapLayer) – An exposure layer.
set_sum_field_name(value=None)[source]

Set field name for the sum column.

Parameters:value (string) – A name of sum field
Returns:None
sum_field_name()[source]

Return field name for the sum column.

update_keywords(layer, keywords)[source]

It is a wrapper around self._keyword_io.update_keywords

Parameters:
  • layer (QgsMapLayer) – Layer you want to get the keywords for.
  • keywords (dict) – Dict of keywords to apply to the existing keywords.
Raises:

All exceptions are propagated.

validate_keywords()[source]

Check if the postprocessing layer has all needed attribute keywords.

This is only applicable in the case where were are not using the AOI (in other words self.aoi_mode is False). When self.aoi_mode is True then we always use just the defaults and don’t allow the user to create custom aggregation field mappings.

This method is called on instance creation and should always be called if you change any state of the aggregator class.

On completion of this method the self.is_valid flag is set. If this flag is not True, then no aggregation or postprocessing work will be carried out (these methods will raise an InvalidAggregatorError).

write_keywords(layer, keywords)[source]

It is a wrapper around self._keyword_io.write_keywords

Parameters:
  • layer (QgsMapLayer) – Layer you want to get the keywords for.
  • keywords (dict) – Dict of keywords to write.
Raises:

All exceptions are propagated.