8

I am trying to merge two partially overlapping rasters into a single raster. Where they overlap, I would like to take the maximum value from the 2 rasters.

The rasters represent radio coverage from two different base stations.

I cannot find any way to do this and all similar questions appear to be unanswered. I can merge or add but cannot retain the maximum in the overlapping areas.

3 Answers 3

6

I recently discovered the GRASS tool r.series in the QGIS toolbox. If you set the Aggregate operation to Maximum it will give you the pixel that has the highest value. It works even if the extent of the 2 layers do not match and if the pixel size is different but will not work if the CRS's are different.

3
  • Much thanks. After beating my head against the wall for 5 hours this finally worked!!!!
    – user105727
    Mar 3, 2022 at 4:51
  • 3
    That’s great! It’s traditional to accept the answer so it gets a green check mark and other people down the line know it works.
    – Baswein
    Mar 3, 2022 at 4:54
  • thanks again, hopefully done!
    – user105727
    Mar 4, 2022 at 6:28
1

I would do this calculation on the SAGA raster calculator on QGIS, using an ifelse clause:

ifelse(gt(a,b), a, b)

which means: if a is greater than b, then output value a, if this condition is not true, output value from b. This is, therefore, the maximum value.

Observation: I believe that, prior to this calculation, the rasters should be on the same grid. If they are not, it is possible to adjust them by picking a pixel size value and an extent, preferentially the pixel size should be small enough that the information in both rasters is kept, and resample both rasters using Warp (reproject) tool.

3
  • This is close. But the rasters only overlap partially and the formula is not returning anything where they do not overlap. I assume that the evaluation is not successful where either a and b is not defined and therefore the comparison is failing.
    – user105727
    Mar 2, 2022 at 23:18
  • I suspect this is what you meant when you said they need to be on the same grid, so I will work on this assumption trying to match their grid.
    – user105727
    Mar 2, 2022 at 23:47
  • Resampling with WARP does not work. My extents don't change and the no values remain no values (They do not change)
    – user105727
    Mar 3, 2022 at 1:52
1

Try this in the raster calculator:

(a>b) * a + (b>a) * b

2
  • This doesn't work in the GDAL Raster Calculator and in the SAGA Raster Calculator it works but suffers the same problem as the other SAGA solution in that it does not include parts of the raster that don't overlap.
    – user105727
    Mar 4, 2022 at 18:01
  • It should work in the Raster Calculator of QGIS (Top Menu Raster -> Raster Calculator) I´ve been using this solution with three layers recently and it works well. But in my case all the layers where in the same place and overlapping at 100%
    – Oruiz
    Mar 4, 2022 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.