QGIS raster calculator is confusing me and I have no idea how to perform a very simple task.

I have 2 rasters, A and B:

Raster A has 9999 values on all pixels. Raster B has different values including no data pixels.

I want Raster A pixel to = Raster B pixel where B != null

Which means Raster C(output) is 9999 Except where Raster B has values

  • What have you tried? See for example something like: Conditional calculation - QGIS Raster Calculator or GRASS r.mapcalculator
    – Bera
    Commented Mar 3, 2020 at 15:27
  • 1
    I tried this, didn't work: (("slope_clipped@1">0) * "9999@1" = "slope_clipped@1") + (("slope_clipped@1">0) * "9999@1" = 9999) I.E.: if(rasterB_pixel >0){ rasterA_pixel = rasterB_pixel } else{ rasterA_pixel = 9999 //do nothing }
    – Steffan
    Commented Mar 3, 2020 at 15:51

2 Answers 2


The QGIS-documentation provides a very similar example-task: https://docs.qgis.org/3.4/en/docs/user_manual/working_with_raster/raster_calculator.html

According to the documentation, the following should work:

("slope_clipped@1" > 0) * "slope_clipped@1" + ("slope_clipped@1" = 0) * 9999

Naturally, if you didn't describe your data correctly to us, this wont work.


You can do it without raster calculator, using Fill NoData cells. Input is Raster B, Fill value is 9999.

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.