Create mask raster layer

Create a mask raster layer by applying a user-defined evaluation function band-wise to a source raster layer.

Usage:

  1. Open the algorithm from the processing toolbox.

  2. Select a raster layer to be masked and modify the python script to fit your needs, then click run.

    ../../../../_images/create_mask.png
  3. The output raster can be found under Rasters in the Data Source Panel

Parameters

Raster layer [raster]

Raster layer to be processed band-wise.

Function [string]

Python code defining the evaluation function. The defined function must return a binary-valued array with same shape as the input array.

Default:

import numpy as np

def function(array: np.ndarray, noDataValue: float):
    # if source no data value is not defined, use zero as no data value
    if noDataValue is None:
        noDataValue = 0

    # mask no data pixel
    marray = np.not_equal(array, noDataValue)

    # mask inf and nan pixel
    marray[np.logical_not(np.isfinite(array))] = 0

    # include further masking criteria here
    pass

    return marray

Outputs

Output raster layer [rasterDestination]

Raster file destination.

Command-line usage

>qgis_process help enmapbox:CreateMaskRasterLayer:

----------------
Arguments
----------------

raster: Raster layer
    Argument type:  raster
    Acceptable values:
            - Path to a raster layer
function: Function
    Default value:  import numpy as np

def function(array: np.ndarray, noDataValue: float):
    # if source no data value is not defined, use zero as no data value
    if noDataValue is None:
        noDataValue = 0

    # mask no data pixel
    marray = np.not_equal(array, noDataValue)

    # mask inf and nan pixel
    marray[np.logical_not(np.isfinite(array))] = 0

    # include further masking criteria here
    pass

    return marray

    Argument type:  string
    Acceptable values:
            - String value
            - field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field
            - expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression
outputRaster: Output raster layer
    Argument type:  rasterDestination
    Acceptable values:
            - Path for new raster layer

----------------
Outputs
----------------

outputRaster: <outputRaster>
    Output raster layer