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?
2 Answers
"... 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
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.