Interactive Raster Expression Tester
Use this mini tool to test QGIS-style raster math before you run it in the Raster Calculator. Enter sample pixel values for three bands (A, B, and C), type an expression, and calculate the output instantly.
What is the Raster Calculator in QGIS?
The Raster Calculator in QGIS is a cell-by-cell math engine for raster layers. It lets you create a new raster by applying formulas to existing raster bands. If you can write the expression, QGIS can calculate it for every pixel in your extent.
This is useful for remote sensing, terrain analysis, environmental modeling, land cover logic, and fast geoprocessing workflows where vector tools would be slower or less precise.
Where to find it
- Menu path: Raster > Raster Calculator
- Alternative: From the Processing Toolbox, search for "Raster calculator"
- Output: You can save as GeoTIFF (or another format), and optionally add the result to your project immediately
QGIS raster calculator syntax basics
1) Referencing raster bands
In QGIS expressions, a band is usually referenced like this:
2) Arithmetic operators
+addition-subtraction*multiplication/division^power (depending on context/tools, many users preferpow()style in expressions)
3) Logical and conditional patterns
You can build masks and condition-based outputs using comparisons and boolean logic. Typical logic includes:
>,<,>=,<=,=- Combining masks with AND/OR logic patterns
- Creating binary outputs (1 for true, 0 for false)
Common raster calculator formulas in QGIS
NDVI (Normalized Difference Vegetation Index)
One of the most common formulas:
Values typically range from -1 to 1. Higher values usually indicate healthier green vegetation.
NDBI (Built-up index style)
Simple threshold mask
If you want pixels above a threshold:
This creates a binary raster where steep areas become 1 and all other pixels become 0.
Weighted suitability map
NoData handling tips
NoData can quietly break analysis. Before you run a final model:
- Confirm each input layer has the expected NoData value.
- Use safe denominators for division operations (for example adding a tiny epsilon like
0.000001). - Clip and align rasters first so extents, resolutions, and CRS are consistent.
- Set output data type appropriately to avoid clipping floating-point results into integers.
Performance and quality best practices
- Align grids first: same pixel size, projection, extent.
- Use compact formulas: avoid repeated heavy operations when possible.
- Check output type: float outputs are often required for index calculations.
- Preview statistics: inspect min/max and histogram after calculation.
- Style with meaningful ramps: visualization can hide logic errors if not checked.
Step-by-step workflow example
Goal: Create NDVI from two bands
- Load NIR and Red raster bands into QGIS.
- Open Raster Calculator.
- Build expression:
("NIR@1" - "RED@1") / ("NIR@1" + "RED@1"). - Set output file path and choose Float32 type.
- Run the tool.
- Apply a color ramp and inspect value distribution.
- Optionally reclassify NDVI into vegetation classes.
Troubleshooting quick list
- All zeros? Check integer output type and denominator behavior.
- Unexpected stripes or shift? Inputs may not be aligned to the same grid.
- Huge values? Division by tiny/zero denominator or wrong scaling factor.
- Expression error? Verify band names and parentheses carefully.
Use the calculator above as a dry-run tool
The interactive calculator at the top of this page gives you a quick way to test expression logic with sample pixel values before running full-raster processing in QGIS. It is especially helpful for validating formulas, checking sign direction, and ensuring scaling choices make sense.
Once your logic looks right, transfer the expression into QGIS Raster Calculator, replace A/B/C with real band references, and run on the full dataset.