QGIS Raster Calculator – Set Values to 0 Instead of No Data

nodataqgisraster

I have a landcover map with different values for the landuse options e.g. 190 for commercially used areas. Now I want to extract only these areas using the Raster Calculator with the expression

"Raster@1" = 190

This works fine, the resulting Raster contains value 1 for all cells which where 190 before (as it is supposed to) but no data values (high negative values) for all other cells, which I need to be zero instead. When I did the same operation to other rasters, QGIS would set the other cells to 0, which in this case is necessary for me to add the result raster to another raster later on.

Any ideas how I can avoid that QGIS sets the cells to no data cells? And what could be a reason that it deals differently with rasters of the same format when applying the same operation with the raster calculator? Both rasters are .tif but from different sources.

Best Answer

I just found the SAGA tools and the better raster calculator provided. I solved the problem using the following formula:

ifelse(eq(a,190), 1, 0)

which actively sets all cells with a value other than 190 to zero.

Edit: I just found the reason why QGIS dealt differently, too: I was wrong stating that both rasters had the same format. In the first case my input raster was in ASCII format and QGIS set zeros. Doing the same operation with a tif format, it sets no data values.