I'm using the raster calculator from core in QGIS and I need to generate a new tif raster file (mask) from the nodata values of another tif raster file. I tried isnull(), but no luck. Any one can help?

  • Seems like raster calc just passes NA to the new raster the moment it encounters NA - though this post seems to indicate that someone did do calcs on NA values. I can't get it to work though, trying rast@1 = -9999 where -9999 is my NoData value. gdal_translate is supposed to allow removing nodata values (-a_nodata none) but I can't get that to work either.
    – Simbamangu
    Commented May 4, 2012 at 14:54

2 Answers 2


"... I need to generate a new tif raster file (mask) from the nodata values of another tif raster file."

You can use gdalwarp, via the command line, to convert a nodata value to an alpha mask:

gdalwarp -dstalpha -srcnodata "0 0 0" -co "ALPHA=YES" "raster_w-nodata.tif" "raster_w-alpha.tif"

You will want to read up on the creation options for GeoTIFF, or whatever gdal-supported output raster format you need.

I do not see a simple way to do this in QGIS, yet. Most of the GDAL (Raster menu) tools work with the utilities and extra Python script bundled with GDAL. Since the underlying utilities of GDAL have a myriad of choices to suit many different scenarios, you may run into limitations of what is generally available via the GUI tools in QGIS.

In those instances, try directly using GDAL's command line utilities or load GDAL's Python binding into a Python script and leverage GDAL from there.


dakcarto's answer worked for me, with the following modification:

gdalwarp -dstalpha -srcnodata "-9999" -co "ALPHA=YES" "rast.tif" "rast_w-alpha.tif"

Assuming your raster only has one band, like mine did. The second band in your new GeoTIFF is now the mask for data (value 0) and nodata (value 255).

I hope someone can put this into a simple plugin for QGIS 2.0, because it took me two hours to find this, and I expected to be able to just use the nodata value in the QGIS raster calculator...

  • There is also an option, in QGIS 2 at least, under Raster menu | Analysis | Fill 'nodata' Commented Jul 24, 2013 at 21:26

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.