[GIS] QGIS raster image transparency, NO DATA value for all raster images

nodataqgisrastertransparency

I'm working with sets of aerial images in QGIS which are geocoded including orientation i.e. rotated.

After loading images QGIS draws a black box around each image that extends from the far west to far east pixel and from the far north to far south pixel. Within this black box lays the actual image in it's correct orientation.

To get rid of this black box I currently enter 0 in Layer Properties / Transparency / Additional NODATA value but the change has to be made on every single image. Unfortunately the transparency setting is not part of the Style definition and therefore cannot be copied from one to all other raster layers / images.

Is there better way to add a global NODATA value to all raster data in current workspace?

Raster Calculator won't work as there are no NODATA areas in the actual image files.

Best Answer

You might want to look at VRTs (Virtual Rasters).

You can build these in QGIS, using Raster > Miscellaneous > Build virtual raster (Catalog), or directly on the command line using gdalbuildvrt

VRTs are small XML files which stitch together lots of rasters into one, "big" virtual raster which can be loaded and processed as if it was a single raster.

If you set the sourcenodata to "0 0 0" (assuming 3 bands, r,g,b) it should set pixels to transparent by setting the nodata value to 0. You probably want settings to look something like this:-

vrt settings for nodata values

I don't have any batches of aerial imagery to hand to test this, but it should allow you to merge all your images and set a single NODATA value for all of them across multiple bands.

I tried this by creating a VRT from a single aerial raster (without a nodata value) and it had the desired effect of setting nodata to 0, and the empty areas to transparent, so it's worth a try.

Also tried this from the Processing/GDAL menu in QGIS 2.16.3, and this option was missing. So use the old-style menu option or the command line to try this out.

Related Question