4

I have a raster (DEM) and want to replace a few cell's values with the values from another raster in QGIS. I would have done this with the "over" tool in the raster calculator in ArcGIS.

Specifics: To potentially restore a mire, I want to model how the water flows if dams were to be put into place across some ditches. So, I have the original DEM and would like to add the dams to it (to then do an flow accumulation analysis). I cannot just add a few meters to the cell's values, because the dams are supposed to go across the ditches (so 90 degrees to the ditches) ... so, a constant would not result in an even dam, but a v-shaped one.

Is somebody able to help?

  • You can use the Raster Calculator or Using the QGIS Raster Calculator – gene May 22 '14 at 18:03
  • How can I replace values in the QGIS raster calculator? I know I can add/subtract/multiply/divide, but I want to replace them with the new values from the second raster. I might be missing something very obvious!? – Julia May 22 '14 at 18:09
  • Assuming raster 2 is just the dams, wouldn't R1 = R1 + (R2-R1) work? – Chris W May 22 '14 at 18:27
  • Yes, that would work. Thanks a lot. It obviously wasn't as difficult as I thought it would be. – Julia May 22 '14 at 18:43
2

As gene mentions, the raster calculator can also be used to solve this in QGIS. Note there is the one that comes with QGIS as well as one (RasterCalc) or more plugins available that may have different capablities. There are several ways you could approach the problem with different formulas (such as a conditional statement or diff function).

Since your question already sets the parameters you have a second raster with correct values, I make the assumption that the second raster is just the pixels that are top of dams at the appropriate elevation (constant value) and everything else null. As you said in the question, just adding them won't work since it doesn't account for the relative difference between top of dam and ground. You need to add the difference between the two rasters to the first raster to effectively replace the values of overlap.

You can first get the difference by R3=R2-R1. Then you must convert the nulls to 0, as mathematical operations on a null result in a null. Once converted, you can use R4=R1+R3 to get your final result.

  • This makes sense and should work, but I can't seem to get it to work. R3 (the resulting DEM) only has the dams in it and the rest is NoData. As input, I have the DEM as a geotiff with a certain extent and the dams with the same extent but "noData" around the dams. – Julia May 23 '14 at 9:06
  • If I seperate the two calculations, R2-R1 works fine, but adding the result from that to R1 doesn't seem to work (everything around the dams become NoData). – Julia May 23 '14 at 9:31
  • @Julia You're right, I forgot a basic property of null - any math on a null results in a null. I've corrected my answer. – Chris W May 23 '14 at 19:47
1

Chris was right with his equation, but you have to do it in steps.

If you have the dams in a raster file with the cells that represent the dams having the elevation data and the other cells being nodata, you can subtract the dem from the dams layer in the raster calculator (R2-R1 in Chris' answer). You then have to reclassify the nodata values to zero. you can do that in QGIS 2.2.0 under the SAGA processing tools --> Grid Tools --> Reclassify Grid Values. The newly classified layer can then be added to the original DEM.

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.