Monday, 12 March 2018

Replacing raster values in one raster with another raster in QGIS ... how to?


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?



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...