I am building a groundwater model and I need to assign elevations to the base of geologic units (where the unit is present) and at a minimum thickness where the unit is not present. I have a topography raster that covers my entire model area and raster of the geologic units that cover only the area where the unit is present.

I want to use raster calculator to calculate layers base elevation based on whether the unit is present or not.

I tried using a Boolean expression in raster calculator.
For example, for layer 1. I want to assign the base elevation of the layer to the base of FILL where the FILL unit is present and where the unit is not present, assign base of layer to 1 m below the topography.

I was using the following expression

((("topography" - "FILL" >=1)* "FILL") + (("topography"-"FILL"<1)* topography_minus_1)    

For some reason, this is not working and it only calculates a really tiny area instead of completely across the domain.

I thought it might have to do with the FILL unit being on a different grid to topography, so I tried r.resample to try and expand the extent of the FILL unit but when I put in the extent of the topography raster and try and resample, it crashes and then QGIS shuts down.

FILL dimensions X: 865 Y: 559 Bands: 1 TOPOGRAPHY dimensions X: 3295 Y: 2056 Bands: 1

How can I make these layers from my rasters based on a boolean expression?

3 Answers 3


I would first try a very simple procedure, try assigning the extension of the TOPOGRAPHY layer to the FILL layer.

Simply place the FILL@ layer in the Raster calculator and select the TOPOGRAPHY layer as the extension.

Give a name to the output layer, for example: FILL2. Then with FILL2 apply the operation you describe


For many years I was dealing with this exact issue. There are multiple problems to overcome with geology layers, and I decided to sort it out with python code. Especially because of number of geological layers in models it would be otherwise terrible tedious work.

This whole problem starts with raster QGIS raster calculator not being able to work with null values - more about it in my question here Working with NaN/null and different extents in QGIS Raster calculator?.

So you simply can't use it for what you want to do. You have to use depending on your skills some other process / tool / coding. From my perspective the most efficient way is to completely change the process in the way your model nodes get these values assigned as points sampling your small geology presence raster - 1 if it hits the presence, 0 if not.

If you really really need to work with raster, you need to use other tools - gdalwarp (in QGIS top menu Raster / Projections / Warp) is your best friend for resizing, and dealing with none / null / nodata values. And you can also have a look at gdal_calc.py.


Merge / join TOPOGRAPHY layer to the FILL layer.

  • 5
    Welcome to GIS SE. As a new user, please take the Tour. Answers, and especially late answers, need to provide details. If the answer is a single sentence, if could be a comment instead. Since this is so brief, it was automatically placed in the "low quality post" queue, and might be deleted. Please improve your Answer by providing a documentation link and/or a graphic to explain what it is that you are suggesting.
    – Vince
    Jul 2, 2022 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.