In QGIS - I have an irregularly shaped raster - I wish to clip an irregular area out of it (call it raster A) with that area set to null.

I masked the area (vector polygon) I want to remove and used warp > reproject to create the second raster (lets call it B) that effectively contains the portion of raster A I want to set to null.

I intended to use raster calculator to subtract raster B from raster A which would leave the areas to be removed with value 0, and I could then reproject this setting 0 to null - however this doesnt work as outside the masked area 'A - null = null' and I end up with a calculated raster of 0 in only the area I want to remove, and null everywhere else.

How can I treat the areas on raster B that are null as zero in the calculation? Alternatively, is there any less convoluted way I can complete this process?


1 Answer 1


Use nan_to_num to replace nans with zeroes. In the calculator, it will look like this:

nan_to_num(A@1) + nan_to_num(B@1)

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.