Module: safe.engine.interpolation

Interpolation from hazard to exposure layers.

Provides interpolation functionality to assign values from one layer instance to another irrespective of layer types.

safe.engine.interpolation.assign_hazard_values_to_exposure_data(hazard, exposure, layer_name=None, attribute_name=None, mode='linear')[source]

Assign hazard values to exposure data

This is the high level wrapper around interpolation functions for different combinations of data types.

Args:
  • hazard: Layer representing the hazard levels

  • exposure: Layer representing the exposure data

  • layer_name: Optional name of returned layer.

    If None (default) the name of the exposure layer is used for the returned layer.

  • attribute_name:

    If hazard layer is of type raster, this will be the name for new attribute in the result containing the hazard level. If None (default) the name of hazard layer is used.

    If hazard layer is polygon and exposure layer raster, this will be the name of the new attribute containing the raster value at each point.

    If hazard and exposure layers are both of type vector, this attribute is ignored.

    If hazard and exposure layers are both of type raster, this attribute is ignored.

  • mode:

    Interpolation mode for raster to point interpolation only

Returns:
Layer representing the exposure data with hazard levels assigned.
Raises:
Underlying exceptions are propagated

Note:

Admissible combinations of input layer types are

Exposure | Raster Polygon Line Point

Polygon | Y Y Y Y Raster | Y Y Y Y

with the following methodologies used:

Polygon-Point: Clip points to polygon and assign polygon attributes
to them.

Polygon-Line: * Not Implemented * Polygon-Polygon: * Not Implemented * Polygon-Raster: Convert raster to points, clip to polygon,

assign values and return point data
Raster-Point: Bilinear (or constant) interpolation as currently
implemented

Raster-Line: * Not Implemented * Raster-Polygon: Calculate centroids and use Raster - Point algorithm Raster-Raster: Exposure raster is returned as is

The data type of the resulting layer depends on the combination of input types as follows:

Polygon-Point: Point data Polygon-Line: N/A Polygon-Polygon: N/A Polygon-Raster: Point data Raster-Point: Point data Raster-Line: N/A Raster-Polygon: Polygon data Raster-Raster: Raster data

safe.engine.interpolation.check_inputs(hazard, exposure, layer_name, attribute_name)[source]

Check inputs and establish default values

Args:
  • hazard: Hazard layer instance (any type)
  • exposure: Exposure layer instance (any type)
  • layer_name: Name of returned layer or None
  • attribute_name: Name of interpolated attribute or None
Returns:
  • layer_name
  • attribute_name
Raises:
VerificationError
safe.engine.interpolation.interpolate_polygon_lines(source, target, layer_name=None)[source]

Interpolate from polygon vector layer to line vector data

Args:
  • source: Vector data set (polygon)

  • target: Vector data set (lines)

  • layer_name: Optional name of returned interpolated layer.

    If None the name of target is used for the returned layer.

Returns:
Vector data set of lines inside polygons

Attributes are combined from polygon they fall into and line that was clipped.

Lines not in any polygon are ignored.

safe.engine.interpolation.interpolate_polygon_points(source, target, layer_name=None)[source]

Interpolate from polygon vector layer to point vector data

Args:
  • source: Vector data set (polygon)

  • target: Vector data set (points)

  • layer_name: Optional name of returned interpolated layer.

    If None the name of target is used for the returned layer.

Output
I: Vector data set; points located as target with values interpolated from source
Note
All attribute names from polygons are transferred to the points that are inside them.
safe.engine.interpolation.interpolate_polygon_raster(source, target, layer_name=None, attribute_name=None)[source]

Interpolate from polygon layer to raster data

Args
  • source: Polygon data set

  • target: Raster data set

  • layer_name: Optional name of returned interpolated layer.

    If None the name of source is used for the returned layer.

  • attribute_name: Name for new attribute.

    If None (default) the name of layer target is used

Output
I: Vector data set; points located as target with
values interpolated from source
Note:
Each point in the resulting dataset will have an attribute ‘polygon_id’ which refers to the polygon it belongs to.
safe.engine.interpolation.interpolate_polygon_vector(source, target, layer_name=None)[source]

Interpolate from polygon vector layer to vector data

Args:
  • source: Vector data set (polygon)

  • target: Vector data set (points or polygons) - TBA also lines

  • layer_name: Optional name of returned interpolated layer.

    If None the name of target is used for the returned layer.

Output
I: Vector data set; points located as target with values interpolated
from source
Note:
If target geometry is polygon, data will be interpolated to its centroids and the output is a point data set.
safe.engine.interpolation.interpolate_raster_raster(source, target)[source]

Check for alignment and returns target layer as is

safe.engine.interpolation.interpolate_raster_vector(source, target, layer_name=None, attribute_name=None, mode='linear')[source]

Interpolate from raster layer to vector data

Args:
  • source: Raster data set (grid)

  • target: Vector data set (points or polygons)

  • layer_name: Optional name of returned interpolated layer.

    If None the name of V is used for the returned layer.

  • attribute_name: Name for new attribute.

    If None (default) the name of R is used

Returns:
I: Vector data set; points located as target with values
interpolated from source

Note: If target geometry is polygon, data will be interpolated to its centroids and the output is a point data set.

safe.engine.interpolation.interpolate_raster_vector_points(source, target, layer_name=None, attribute_name=None, mode='linear')[source]

Interpolate from raster layer to point data

Args:
  • source: Raster data set (grid)

  • target: Vector data set (points)

  • layer_name: Optional name of returned interpolated layer.

    If None the name of target is used for the returned layer.

  • attribute_name: Name for new attribute.

    If None (default) the name of layer source is used

  • mode: ‘linear’ or ‘constant’ - determines whether interpolation

    from grid to points should be bilinear or piecewise constant

Output
I: Vector data set; points located as target with values
interpolated from source
safe.engine.interpolation.make_circular_polygon(centers, radii, attributes=None)[source]

Create circular polygon in geographic coordinates

Args:

centers: list of (longitude, latitude) radii: desired approximate radii in meters (must be

monotonically ascending).

Can be either one number or list of numbers attributes (optional): Attributes for each center

Returns
Vector polygon layer representing circle in WGS84
safe.engine.interpolation.tag_polygons_by_grid(polygons, grid, threshold=0, tag='affected')[source]

Tag polygons by raster values

Args:
  • polygons: Polygon layer
  • grid: Raster layer
  • threshold: Threshold for grid value to tag polygon
  • tag: Name of new tag
Returns:
Polygon layer: Same as input polygon but with extra attribute tag
set according to grid values

This module forms part of the InaSAFE tool.

Previous topic

Module: safe.engine.utilities

Next topic

Package::safe.engine.impact_functions_for_testing

This Page