Stay Connected with the Boundless Blog

One Processing Raster Calculator To Rule Them All

In the road to QGIS 3, the Processing framework is seeing some interesting changes. Some of them have just started taking shape, such as adapting algorithm execution to use the recently-added Task Manager, while others have been added and well-tested already. The most important one of those changes is probably the refactoring of the parameters architecture, which was implemented along with the QGIS developers at Camp2Camp. Now, parameters for algorithms have a clearer implementation, and it’s easy to do things such as define custom parameters (without having to add them to the core of Processing), of custom interfaces for a given parameter. It also makes possible to handle parameters that might behave differently in the modeler, making it more robust to run all algorithms as part of a model, and also easier for the user.

A good example of how this more flexible parameters architecture help implementing new algorithm is the Raster Calculator. A new processing Raster Calculator algorithm has been added, which mimics the look and behavior of the native QGIS calculator (and internally uses the same classes), but can be run in the modeler or the batch processing interface. This algorithm should replace all other calculators available in Processing (GDAL, GRASS; SAGA, etc), since it is more robust and versatile, and also has a nicer interface, as can be seen below.

QGIS Raster Calculator

The calculator can be called from the toolbox, and its usage is similar to the current native calculator.

When used in the modeler, the interface is also similar, and adding a reference to a model layer in the calculator expression is intuitive.

QGIS Raster Calculator

Preconfigured expressions are also available, and the user can add new ones.

QGIS Raster Calculator

Reusing one of such expressions is easy, and can be done without typing, using the corresponding dialog for selecting the layers to use for each of the variables in the expression.

When running the raster calculator from the console, only the expression is required (but extent and cellsize, as well as the output path, can be specified if needed)

processing.runalg(“qgis:rastercalculator”, {“EXPRESSION”:”dem25@1 * 10″})

Layers from files not currently open in the QGIS project can also be used, and their base filename is used to refer to them in the expression. In this case, the layers to use must be passed explicitly (in the case of using project layers, they are found in the project using their name)

processing.runaalg(“qgis:rastercalculator”, {“LAYERS”: “/Users/myusername/gisdata/dem25.tif”,”EXPRESSION”:”dem25@1 * 10″})

Boundless OpenLayers can display tiles from a variety of devices.

We expect to adapt other algorithms so they can integrate better in both Processing and QGIS itself, with the idea of providing all the potential that Processing can offer, while still creating a good user experience for those less-advanced users that might feel intimidated by the toolbox and the Processing interface.