Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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? Thanks

share|improve this question
    
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 May 4 '12 at 14:54

2 Answers 2

up vote 2 down vote accepted

"... 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.

share|improve this answer

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...

share|improve this answer
    
There is also an option, in QGIS 2 at least, under Raster menu | Analysis | Fill 'nodata' –  Oscar van Vliet Jul 24 '13 at 21:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.