safe.gis.qgis_raster_tools module

Convert QgsRasterLayer to QgsVectorLayer

safe.gis.qgis_raster_tools.clip_raster(raster, column_count, row_count, output_extent)[source]

Clip raster to specified extent, width and height.

Note there is similar utility in safe_qgis.utilities.clipper, but it uses gdal whereas this one uses native QGIS.

Parameters:
  • raster (QgsRasterLayer) – Raster
  • column_count (Int) – Desired width in pixels of new raster
  • row_count (Int) – Desired height in pixels of new raster
  • output_extent (QgsRectangle) – Extent of the clipped region
Returns:

Clipped region of the raster

Return type:

QgsRasterLayer

safe.gis.qgis_raster_tools.pixels_to_points(raster, threshold_min=0.0, threshold_max=inf, field_name='value')[source]

Convert raster to points.

Areas (pixels) with threshold_min < pixel_values < threshold_max will be converted to point layer.

Parameters:
  • raster (QgsRasterLayer) – Raster layer
  • threshold_min (float) – Value that splits raster to flooded or not flooded.
  • threshold_max (float) – Value that splits raster to flooded or not flooded.
  • field_name (string) – Field name to store pixel value.
Returns:

Point layer of pixels

Return type:

QgsVectorLayer

safe.gis.qgis_raster_tools.polygonize(raster, threshold_min=0.0, threshold_max=inf)[source]

Raster polygonizer.

Function to polygonize raster. Areas (pixels) with threshold_min < pixel_values < threshold_max will be converted to polygons.

Parameters:
  • raster (QgsRasterLayer) – Raster layer
  • threshold_min (float) – Value that splits raster to flooded or not flooded.
  • threshold_max (float) – Value that splits raster to flooded or not flooded.
Returns:

Polygonal geometry

Return type:

QgsGeometry

safe.gis.qgis_raster_tools.polygonize_gdal(raster, threshold_min=0.0, threshold_max=inf)[source]

Function to polygonize raster. Areas (pixels) with threshold_min < pixel_values < threshold_max will be converted to polygons.

Parameters:
  • raster (QgsRasterLayer) – Raster layer
  • threshold_min (float) – Value that splits raster to flooded or not flooded.
  • threshold_max (float) – Value that splits raster to flooded or not flooded.
Returns:

Polygonal geometry

Return type:

QgsGeometry