
Map Algebra Calculator Plugin for QGIS
I've released a new QGIS plugin: the Map Algebra Calculator. It's a raster calculator in the spirit of the familiar QGIS Raster Calculator, but you choose the engine that does the work: PCRaster map algebra, the GDAL raster calculator (numpy syntax) or GRASS r.mapcalc.
In this video I show how to install the plugin and use it to go from a digital elevation model to subcatchments, in a single script:
Why I developed this plugin
The Map Algebra Calculator fills a gap between the map algebra tools in the QGIS Processing Toolbox and the Python API of the processing providers. Take PCRaster as an example. There are already good ways in for different kinds of users:
- Beginners use the PCRaster Tools plugin: every PCRaster operation is a Processing tool with its own dialog.
- More advanced users chain those tools in the Model Designer to automate a workflow.
- Expert users write Python against the native API of the processing provider, for example PCRaster Python.
But there was no tool for the people in between: those who know map algebra and want to write slope(dem) > 0.1 and landuse == 3 directly, without clicking through one dialog per operation and without writing a Python script. That is who this plugin is for.

What the plugin does
You open the calculator from the Raster menu or with its icon in the Plugins toolbar. These are the main features:
- Three engines. PCRaster gives you the full map algebra, including terrain and hydrology functions such as slope, lddcreate, accuflux, streamorder and subcatchment. GDAL uses numpy syntax, as in gdal_calc. GRASS runs r.mapcalc through QGIS Processing, including neighbour cells such as dem[-1, 0].
- One syntax for all engines. Write conditions the way you read them: and, or, not, xor(a, b), ranges such as 0.05 < slope < 0.2 and x if condition else y. The plugin translates them for the engine you choose. For GRASS you see the r.mapcalc translation live while you type.
- Multi-line scripts. Use intermediate variables over several lines; the last line is the result.
- Help while you type. Every raster layer gets a reference name, functions are grouped by category with a short description and a link to the documentation, and the expression is checked as you type. Common mistakes, such as forgetting brackets around comparisons with &, get a clear message instead of a wrong map.
- Value scales for PCRaster. You set the value scale per input. On auto, the plugin reads it from PCRaster .map files and guesses it for other rasters (scalar for floating point, nominal for integers).
- A common output grid. All inputs are resampled onto the grid of a layer you choose, optionally with another cell size, so you can combine rasters with different extents and resolutions.
- Output as GeoTIFF, or as PCRaster .map with the PCRaster engine.
- Processing algorithms. The calculator is also available in the Processing Toolbox, with inputs A to F. You can use it in batch processing, in the Model Designer and from Python with processing.run.
- Export as Processing script. Save a calculation as a standalone Processing script, with your layers as parameters. It runs without the plugin, so you can share it with colleagues or students.

Example: From DEM to subcatchments
In the video I use the PCRaster engine to build up a small hydrological analysis step by step:
- slope(dem) calculates the slope. My DEM is an integer raster, so I set its value scale to scalar first.
- slope(dem) > 0.5 selects the steep slopes.
- lddcreate(dem, 1e31, 1e31, 1e31, 1e31) creates the local drain direction network, saved as a .map file. When it is loaded again, the plugin recognises it as an LDD map.
- streamorder(flowdirection) > 8 selects the main rivers using Strahler stream order.
Then the whole analysis comes together in one multi-line script that delineates the subcatchments between the river junctions:
strahler = streamorder(flowdirection)
river = strahler >= 8
riverStrahler = ifthen(river, strahler)
junction = downstream(flowdirection, riverStrahler) != riverStrahler
junctionID = nominal(uniqueid(junction))
subcatchment(flowdirection, junctionID)
Finally I export this calculation as a Processing script, run it from the Processing Toolbox, and show how the calculator algorithms appear in the Model Designer.
Installation
Install Map Algebra Calculator from Plugins ▸ Manage and Install Plugins. The plugin is still experimental, so first tick Show also experimental plugins in the settings of the Plugin Manager. It works with QGIS 3.28 and later, including QGIS 4.
- The GDAL engine works in every QGIS installation.
- The PCRaster engine needs PCRaster in your QGIS Python environment. The PCRaster Tools plugin explains how to install it. PCRaster is not yet available for QGIS 4.
- The GRASS engine needs the GRASS provider of QGIS Processing, which is part of most QGIS installations.
Engines that are not available are disabled in the dialog, with an explanation. You'll find the plugin in the QGIS plugin repository, and the source code, documentation and a small test dataset with example expressions on GitHub.
Try it and let me know
Watch the video to see the plugin in action, then try it on your own data. Found a bug or have an idea for a new feature? Please open an issue on GitHub. I'm curious if the plugin is useful for you.
