5

I am trying to create a single raster file that divides the region of Antwerp, Belgium into 5 categories: high green, low green, agriculture, water, and build-up area. For this, I will have to combine two raster files I already have:

  1. I have a raster that shows at a certain resolution different categories of vegetation. The legend is as follows: 1 = High green (dark green); 2 = low green (light green); 3 = agriculture (yellow); and 4 = other (grey) (see figure below).enter image description here

  2. Another raster shows where there is water in the same area (Legend: 6 = water (blue)) (see figure below where this raster layer is shown on top of the first).enter image description here

What I want to do is to keep the values 1, 2, and 3, and then overwrite the values '4' (other) with '6' (water), but only there where there is water present. The other values '4' should remain the same.

I believe I will have to run some kind of raster calculator line, but I am lost as to which one that would be.

Here is a link to a part of both the vegetation and water datasets: https://we.tl/t-dfXUKHhDxS

0

1 Answer 1

4

Use the Raster Calculator to add selected values from one image to another using the formula:

("Raster 2@1" = 127) * 127 + ("Raster 2@1" != 127) * "Raster 1@1" 

"Raster 1@1" is the image into which the selected values from the "Raster 2@1" image will be inserted and 127 is the value you want to transfer (in my case 127 is grey color in shape of the heart).

___________ Raster1 __________________ Raster2____________________Result

enter image description here__ enter image description here__ enter image description here

** UPDATE 1**

Your raster file with water contains nodata. If you try to check raster values for expression x = integer value and x is Null (nodata) this will always lead to False result (because Null is not a value).

  1. Fill nodata with zeros with the Fill NoData cells tool.
  2. Don't change the expression too much (it makes no sense), use:
("Water@1" = 6) * 6 + ("Water@1" != 6) * "Vegetation@1"
  1. If that doesn't work - clip data to the same extent, make sure that both images have the same data type and pixel size.

enter image description here __ enter image description here __ enter image description here

4
  • I used following syntax in the raster caclulation tool: ("Water@1" = 6)*6 + ("Water@1" != 6)*(("Vegetation@1"=1)*1 + ("Vegetation@1"=2)*2 + ("Vegetation@1"=3)*3 + ("Vegetation@1"=4)*4). There however seems to be a problem with it, as the tool cannot run. I eddited the question to include a link to a part of the datasets.
    – Amber
    Oct 2, 2021 at 9:41
  • @Amber See update. Oct 2, 2021 at 12:41
  • @ComradeChe It would be great if you can add another condition 'Replaced by Water (6) only when Vegetation is Other (4)'. Your current expression puts water in the green/light green area, too.
    – Kazuhito
    Oct 2, 2021 at 23:53
  • @Amber Try this: ("Water@1" = 6 and "Vegetation@1" = 4) * 6 + ("Water@1" != 6 and "Vegetation@1" != 4) * "Vegetation@1" Oct 3, 2021 at 9:03

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.