16

When it comes to NULL value and different extents of rasters I find it extremely cumbersome to use QGIS raster calculator. As far as I am aware there is no way to operate with NaN/Null value. So no matter what you do NaN/NULL in any input become NULL in output.

As far as I am aware you can't do anything like:

(raster1 is NULL)*raster2+(raster1 is not NULL)*raster1

I have similar issue with extents of raster. I have one raster of large extent and second covering only small part of it. I need to update null/zero values of large extent raster to values in small extent raster. If I do calculation below everything off of small extent becomes NULL/Nan.

(largeraster = 0)*smallraster + (largeraster != 0)*largeraster

Is there any way to be able to operate with NULL value in raster calculator? Is there any way to not trash all values in areas where all rasters do not overlap?

6
  • i think SAGA allows this using 0/0 to represent NaN, e.g. this answer
    – Steven Kay
    Commented May 26, 2017 at 22:37
  • As to your second question, to replace nodata cells by the values in small extent raster, SAGA Patching tool (in Processing Toolbox | SAGA | Raster Tools) is powerful and reliable.
    – Kazuhito
    Commented May 29, 2017 at 12:01
  • StevenKay and Kazuhito thank you for your tips, will give it a try
    – Miro
    Commented May 30, 2017 at 1:09
  • I have just perform it with r.patch from the Processing Toolbox. Not an obviuos way to control the right parameters, but I will post a solution once I master it
    – Marco
    Commented Apr 9, 2020 at 12:32
  • @Marco nice revival. I do wonder if this is still problem in QGIS 3.14 as I don't process rasters in QGIS anymore. At that time I ended up writing python script. Also temporarily was using model builder, to change null values to normal values and back. And resizing, copying rasters, burning values from rasters converted to xyz points and other fun stuff as workarounds.
    – Miro
    Commented Apr 9, 2020 at 13:13

1 Answer 1

2

Looking back, your question(s) seems to be about how we fill the void of large raster by a small raster. (I had been thinking two equations in your question were independent).

Using Raster calculator, I think I would suggest a workflow like below:

  1. Change NULL (NoData) of the large raster to 0 (zero).
  2. Merge two rasters (replace zeros of large raster by values from small raster)

(1) Change Null to 0

  • A useful tool is SAGA Reclassify values (QGIS Processing Toolbox | SAGA | Raster tools | Reclassify values).

    We use only replace no data values option. Keep this ticked-on, and set new value for no data values to 0.0 (I think this is default value).

    Make sure replace other values option is off.

    When Run this tool, the NoData cells become 0.

(2) Merge two rasters, only filling voids of large raster

  1. Start Raster calculator

  2. Highlight Large raster on the list and click on Current Layer extent. This will ensure extent of your output.

  3. equation: ("Large@1" != 0) * "Large@1" + ("Large@1" = 0) * "Small@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.