3

I have two rasters: one that is a land cover map (cropland data layer) and the other is a rasterized polygon representing cranberry fields that aren't represented in the land cover raster that I have. I would like to replace the values of the land cover map with the value from the cranberry raster. The values of the land cover raster under the cranberry field raster are variable (from among 8 categories).

I assume the raster calculator is used for this, but I have little experience with that tool.

Image of the cranberry field raster: enter image description here

Image of the land cover raster with cranberry raster overlaying: enter image description here

3 Answers 3

4

OK - after some extensive googling and a fair bit of hair ripped out, I found a solution.

Instead of using a the raster calculator, I used a shape file for the marshes, and "rasterized" them. Instead of specifying a new .tiff, I wrote over the land cover raster that I wanted to update, and boom. Done. Not sure if that is the "correct" way, but it works for what I need.

2
  • Could you walk through these steps with a bit more detail? When I attempt to replicate this in QGIS 3.4, my resulting DEM is identical to my original. The rasterized data does not seem to write over the DEM.
    – BogBody
    Dec 11, 2018 at 20:24
  • I can't seem to get my own protocol to reproduce. I did a bit of searching, though, and found this which may be helpful: gis.stackexchange.com/a/40480/85463 Dec 13, 2018 at 20:09
0

The solution I found was to use the SAGA PATCHING algorithm. This tool takes a raster that has pixels you want to replace in another raster. All nodata pixels in the input raster will become the value of the target raster and all pixels with a value in the input raster keep their values. Essentially replacing the values in the target raster. (I'm using QGIS 3.10 but I believe this has been around for some time)

0

Assuming the layer of land cover map is called "CROP" (varying from 1 to 8), and the cranberry layer is "CRANBERRY", the following steps might be a solution:

  1. Clip both layers to make sure they have the same extent (Raster->Extraction->Clip raster by extent), and you get layers of "CROP_Clipped" and "CRANBERRY_Clipped", respectively.
  2. Check what value the indicator of cranberry fields is. Here, I assume 9.
  3. Check whether the layer CRANBERRY_Clipped is filled with "no data" or a value where there is no cranberry patch. If "no data", search the tool r.null, and replace the null value by 0, and you get a layer of "CRANBERRY_Clippled_NullFilled" consisting of 0 and 9.
  4. Assuming you are assigning a value of 9 to indicate cranberry fields over the layer CROP_Clipped, use Raster calculator and enter ( "CRANBERRY_Clippled_NullFilled@1" > 0 ) * 9 + ( "CRANBERRY_Clippled_NullFilled@1" = 0 )*"CROP_Clipped@1" The command in the parentheses yields a boolean value, 0 or 1, to indicate whether the condition is False or True.

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.