Previously I spent a lot of time to see answer on similar question but neither work with my problem. I have QGIS 3.4 and a DEM where I've to substitute more accurate height in cells that are identified by a "river" coming from rasterization of a poly line (... aligned and same cell width to DEM grid ..). Outside the grid cell of river there are nodata cells, this is the problem I suppose, because ifelse function as 0/1 trick in QGIS doesn't work outside the river cells. Also I'm not able to reclassify nodata in 0, neither of reclassification suggestion work.

When I was young ... I used the simple CON command in ArcView that worked in a very intuitive manner, to realiz this simple question "Where river raster exists pick height from this raster elsewhere maintain height of dem ..) My administration believe to save cash to use open software but do not realize that I spent a lot of time to solve problem, as this, that as I know from previous experience should be intuitive.

2 Answers 2


As of QGIS 3.22, there is a native if statement in the raster calculator that works very similarly to the ArcGIS equivalent. See the changelog entry.

if(river_raster != -9999, river_raster, dem) 

Where -9999 is the nodata value of the river raster

It's worth noting that the raster calculator supports virtual raster (in memory) outputs now too.


In QGIS you may use the raster calculator; you "filter" those pixels in the elevation raster with parentheses: "(river = 1)" (supposing the river pixels are 1), which will evaluate to true, in QGIS these outcomes a 1, which then you multiply; in summary:

"(river_raster = 1)*accurate_raster"

then you filter that output, which, supposing has 0 were there was no river, open the calculator again and use

"(first_output = 0)*not_accurate_raster"
  • Thank you for quick answer, I've previously tried but do not work because my river_raster has nodata value outside the river cells, and output of first statement, althoug correct for height, is limited to river cells. Probaby if exist a statement to set nodata cells to a definite value ... but I've not found it Nov 21, 2019 at 11:07
  • in grass's mapcalc you may use the "if" statement, you may try with the plugin for qgis or on the grass console
    – Elio Diaz
    Nov 21, 2019 at 16:08

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.