0

I have two raster files A and B, raster A lies completely in the extent of raster B. These rasters I want to merge into one while taking the exact values of raster A in the overlapping areas.

1

To achieve this, I first generated two polygons, each with the extent of one of the rasters, via the Tile Index tool and subsequently calculated the difference of the polygons to get the extent of raster B without the overlapping areas of raster A.

2

Then I used the tool Clip Raster by Mask Layer to clip Raster B on that extent to get rid of the overlapping parts.

However, when checking the alignment of raster A with the clipped raster (B), there is a small gap and overlap, respectively, about half a pixel size at the edges of the cut out part, which hence lead to wrong cell values after merging.

3

I then tried to align the rasters with the tool Align Rasters, but could not get the desired result (still gap/overlap). I could not find any tutorial or post explaining it properly.

Do you have any tips on how to do it correctly?

2
  • could you use the raster calculator with something like =A or B
    – Ian Turton
    Sep 16, 2021 at 10:54
  • Thank you for you answer. I did not try it with the raster calculator yet and am not very familiar with it, could you maybe briefly clarify on what expression to use?
    – felix
    Sep 16, 2021 at 11:05

1 Answer 1

0

I Think, the GDAL Tool "merge" should do what you want.

enter image description here

From GDAL documentation: "In areas of overlap, the last image will be copied over earlier ones."
-> You can drag and drop the layers in the layer selection window to be in an order that fits your needs.
enter image description here

3
  • I intend to use the GDAL Merge tool, but the tool cannot deal with overlapping rasters since there is no way to specify wether it should adopt the pixel values from one raster or the other in the overlapping areas. Thus, I have to process the raster files first to get rasters without any overlap before being able to merge them with the Merge tool.
    – felix
    Sep 16, 2021 at 22:41
  • From GDAL documentation: "In areas of overlap, the last image will be copied over earlier ones." -> You can drag and drop the layers in the layer selection window to be in an order that fits your needs.
    – oekoplaner
    Sep 17, 2021 at 9:51
  • This might be the case if both rasters are aligned perfectly. But when I just merge those two rasters, the values of the output are correct only for the cells on the extent of raster B and are incorrect on the extent of raster A (regardless which raster is specified as the first one in the layer section). And I think that is due to the fact that the cells of the rasters are not perfectly aligned so that they overlap each other about half a pixel size. But I do not know if aligning them is even possible somehow.
    – felix
    Sep 17, 2021 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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