4

I have two raster layers. One layer contains the data of the first day a pixel experiences degrees Celsius above a certain threshold. The other layer contains hotspots in Iceland. These hotspots always meet this threshold condition so they skew the data in the first layer.

Therefore, I would like to set the pixels in layer 1 to 0, if they are equal overlap with the hotspots in layer 2.

I tried using the raster calculator in QGIS:

"layer1@1" * ("layer2@1" * 0)

But this gives me a map only consisting of 0's. I would like to only set the values within the raster pixels of layer 2 to 0 in layer 1.

How can I do that with the raster calculator?

2
  • 1
    Just to clarify, do you want to delete the pixels (set to NoData) or set them to 0?
    – Matt
    Commented Sep 6, 2021 at 16:17
  • Yes, I would like to set them to 0 in layer 1, sorry.
    – Thomas
    Commented Sep 7, 2021 at 7:08

1 Answer 1

3

While Raster Calculator does not explicitly implement IF/THEN control statements, you can use a workaround like this:

("layer2@1" = 0) * "layer1@1"

where ("layer2@1" = 0) can be either 0 or 1. It then gets multiplied by the value of layer1@1.

Maybe I am not quite clear about the exact logic you are trying to accomplish (i.e how you want layer1 and/or layer2 to behave), but the idea should be applicable.

Another interpretation of your question/need could be solved with just:

("layer2@1" = "layer1@1") * 0

which sets the pixel to 0 if layer1@1 has the same value as layer2@1.

2
  • 1
    That's what I was going to respond, so I suppose this is the way to do. By the way, @Thomas: You used two multiplications, where one of the three multipliers is a 0 - that of course always returns 0.
    – Babel
    Commented Sep 6, 2021 at 16:23
  • Correct: thanks for pointing out the reason why the result was 0 everywhere. Commented Sep 6, 2021 at 16:24

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.