Tuesday 20 October 2015

How to calculate a new raster based on nodata values from original raster, in QGIS?


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



Answer




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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...