Module: safe_qgis.clipper

InaSAFE Disaster risk assessment tool developed by AusAid -
ISClipper implementation.

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.clipper.clipGeometry(theClipPolygon, theGeometry)[source]

Clip a geometry (linestring or polygon) using a clip polygon.

To do this we combine the clip polygon with the input geometry which will add nodes to the input geometry where it intersects the clip polygon. Next we get the symmetrical difference between the input geometry and the combined geometry.

Args:
  • theClipPolygon - QgsGeometry a Polygon or Polygon25D geometry to clip

    with. Multipart polygons are not supported so the client needs to take care of that.

  • theGeometry - QgsGeometry - linestring or polygon that should be

    clipped.

Returns:
QgsGeometry - clipped to the region of the clip polygon.
Raises:
None
safe_qgis.clipper.clipLayer(theLayer, theExtent, theCellSize=None, theExtraKeywords=None, theExplodeFlag=True, theHardClipFlag=False)[source]

Clip a Hazard or Exposure layer to the extents provided.

Note

Will delegate to clipVectorLayer or clipRasterLayer as needed.

Args:

  • theLayer - a valid QGIS vector or raster layer

  • theExtent either: 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.

    or: A QgsGeometry of type polygon. **Polygon clipping is

    currently only supported for vector datasets.**

  • theCellSize - cell size which the layer should be resampled to.

    This argument will be ignored for vector layers and if not provided for a raster layer, the native raster cell size will be used.

  • theExtraKeywords - Optional keywords dictionary to be added to

    output layer.

  • theExplodeFlag - a bool specifying whether multipart features

    should be ‘exploded’ into singleparts. This parameter is ignored for raster layer clipping.

  • theHardClipFlag - a bool specifying whether line and polygon features

    that extend beyond the extents should be clipped such that they are reduced in size to the part of the geometry that intersects the extent only. Default is False. This parameter is ignored for raster layer clipping.

Returns:
Path to the output clipped layer (placed in the system temp dir). The output layer will be reprojected to EPSG:4326 if needed.
Raises:
None
safe_qgis.clipper.explodeMultiPartGeometry(theGeom)[source]

Convert a multipart geometry to a list of single parts. This method was adapted from Carson Farmer’s fTools doGeometry implementation in QGIS.

Args:
theGeom - A geometry - if it is multipart it will be exploded.
Returns:
A list of single part geometries
Raises:
None
safe_qgis.clipper.extentToGeoArray(theExtent, theSourceCrs)[source]

Convert the supplied extent to geographic and return as as array.

Args:

theExtent: QgsRectangle to be transformed to geocrs. theSourceCrs: QgsCoordinateReferenceSystem representing the original

extent’s CRS.
Returns:
list: Transformed extents in EPSG:4326 in the form
[xmin, ymin, xmix, ymax]
Raises:
None
safe_qgis.clipper.extentToKml(theExtent)[source]

A helper to get a little kml doc for an extent so that we can use it with gdal warp for clipping.

safe_qgis.clipper.tr(theText)[source]

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

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

This module forms part of the InaSAFE tool.

Previous topic

Module: safe_qgis.resources

Next topic

Module: safe_qgis.dock_base

This Page