A QGIS plugin for masking and clipping rasters by condition, raster mask, polygon boundary, or a shape drawn on the canvas.
MaskQ lets you keep only the pixels that meet a condition and write everything else as NoData — or crop the raster entirely to the boundary of the kept pixels.
Four masking modes:
| Mode | Description |
|---|---|
| Value Range | Keep pixels within a min–max range or meeting a threshold (> 500, ≤ 0.3, etc.) |
| Raster Mask | Use a second raster (QA band, cloud mask, water mask) to flag pixels for removal |
| Vector Mask | Keep pixels inside a polygon layer — respects definition queries and selected features |
| Canvas Draw | Draw the shape directly on the map — Freehand, Polygon (click to place vertices), Rectangle (drag a box), or the current map extent. Multiple shapes per run |
Three output operations (Clip and Crop are available for Vector Mask and Canvas Draw):
| Operation | Result |
|---|---|
| Mask | Full raster extent, pixels outside condition → NoData |
| Clip | Crop to bounding box of kept pixels, outside polygon → NoData |
| Crop | Crop to bounding box, all pixel values kept (no masking) |
- Interactive histogram with draggable handles — set your range visually
- Live canvas preview — highlights kept pixels on the map as you adjust the range
- All bands preserved — condition evaluated on one band, output contains every band
- Smart output naming — embeds condition values in the filename (
NDVI_masked_range_0p3to0p8.tif) - QGIS Processing Toolbox integration — use from the Toolbox, Model Builder, or Python console
- Respects layer filters — honours QGIS definition queries on vector layers
- Saves next to the input raster by default, or to any path you choose
- Open QGIS → Plugins → Manage and Install Plugins
- Tick Show experimental plugins in Settings
- Search for MaskQ
- Click Install
- Download
maskq.zipfrom Releases - QGIS → Plugins → Manage and Install Plugins → Install from ZIP
- Browse to the downloaded ZIP → Install Plugin
- Open the panel from Raster → MaskQ or the toolbar icon
- Select your input raster
- Choose a mask method (Value Range / Raster Mask / Vector Mask / Canvas Draw)
- Set the condition — or, for Canvas Draw, click Freehand, Polygon or Rectangle and draw on the map (Esc or right-click cancels; Polygon closes on double-click, Enter or right-click, Backspace removes the last vertex), or press Use Current Extent
- Choose an operation (Mask / Clip / Crop)
- Click Run
The output is saved next to the input raster with a descriptive name, or to the path you specify.
MaskQ registers four algorithms under the MaskQ group (maskbyvaluerange, maskbyraster, maskbyvector, maskbycanvasdraw):
# Value range mask
processing.run("maskq:maskbyvaluerange", {
'INPUT': 'path/to/raster.tif',
'BAND': 1,
'CONDITION_TYPE': 0, # 0=Range, 1=Threshold
'V_MIN': 0.3,
'V_MAX': 0.8,
'OPERATION': 0, # 0=Mask, 1=Clip, 2=Crop
'OUTPUT': 'path/to/output.tif'
})
# Canvas draw mask — polygon(s) supplied as WKT, separate multiple with ';'
processing.run("maskq:maskbycanvasdraw", {
'INPUT': 'path/to/raster.tif',
'GEOMETRY': 'POLYGON((500000 9000000, 501000 9000000, 501000 9001000, 500000 9000000))',
'GEOMETRY_CRS': 'EPSG:32736', # optional — defaults to the raster CRS
'OPERATION': 0, # 0=Mask, 1=Clip, 2=Crop
'OUTPUT': 'path/to/output.tif'
})- QGIS 3.16 or later
- GDAL (bundled with QGIS)
- Local file-based rasters only — XYZ tiles, WMS, and WCS layers are not supported
- Live preview available for Value Range mode only
- Canvas Draw shapes are not saved between QGIS sessions
- Raster mask must use a single band as the flag layer
GPL-2.0-or-later — see LICENSE
Daniel Moyo — moyodanj@gmail.com