8

I am trying to patch two rasters with the raster calculator but I am not finding a way to work with no-data values.

  • Lager@1 has some information I need as the first option, this has no-data -9999 (reading in the properties)

  • Lager@2 has the information I want to complete what is no data in Lager@1

This command does not produce values where Lager@1 is no-data

("Large@1" != -9999) * "Large@1" + ("Large@1" = -9999) * "Lager@2"

I would like to avoid or skip the reclassification because I might have many zeros and I need to perform this with different rasters that might have different no-data formats, for instance, Lager@2 has -99999 instead of -9999.

In GRASS this would be an r.patch task, but I cannot (or I do not know how to) control the order in the r.patch available in the Processing Toolbox.

r.patch input=Lager@1, Lager@2 output=Lager@3

Result of patching of two raster maps containing NULLs using the default settings

2
  • I checked the history of the toolbox and I found the command with r.patch and then I copied and edited for my needs (order of raster files) and pasted the processing.run("grass7:r.patch", {'input':... in the console. It worked, but it was not so frinedly as I would love QGIS to be
    – Marco
    Commented Apr 9, 2020 at 10:07
  • Use Fill NoData cells (see docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/…), also possible in batch mode and change nodata values to 0. I don't know of a direct way, see: gis.stackexchange.com/q/420195/88814
    – Babel
    Commented Mar 9, 2022 at 8:31

2 Answers 2

2

You can do this with r.patch, or using isnull() in r.mapcalc.simple, or using &&& or ||| operators.

2
  • Hi, is ´r.mapcalc` behind the QGIS Calculator? I did not find that information and it would open a door for all its functions and documentation, which is an essential part of a tool. Please confirm my understanding of "r.mapcalc (the QGIS calculator)"
    – Marco
    Commented May 20, 2020 at 7:28
  • Sorry - I was incorrect. You're right, r.mapcalc is not the backend to the QGIS calculator. I've updated the suggestion. You can use r.mapcalc.simple instead of the QGIS calculator.
    – mankoff
    Commented May 20, 2020 at 14:43
0

Solution 1: Replace NoData with fixed, chosen value

You can use the QGIS native algorithm Fill NoData cells to assign a "neutral", numerical value instead of nodata, e.g. 0 (if you add the values afterwards) or 1 (if you multiply). In the tool, you can define the Fill value.

Solution 2: Replace NoData with interpolated value

QGIS also offers access to the GDAL tool Fill NoData that also replaces NoData with a value, but this time not by a fixed, chosen value, but based on an interpolation:

The values for the NoData regions are calculated by the surrounding pixel values using inverse distance weighting. From Documentation

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.