TransWikia.com

How Does QGIS Read 'nodata' in 3 Band Raster Data?

Geographic Information Systems Asked by i.reese on June 4, 2021

I have 3 band GeoTiffs of aerial imagery. The imagery is byte data with values of 0-255 on each band. A ‘nodata’ value has not been assigned on any band. I am assembling these images using a VRT, with no additional arguments, and displaying them in QGIS.


gdalbuildvrt out.vrt *.tif

Is it possible to tell QGIS or gdalbuildvrt to ONLY render transparency in those instances where:

b1 = 0
b2 = 0
b3 = 0

Currently, if you set transparency to zero in QGIS or use:


gdalbuildvrt -srcnodata "0 0 0" out.vrt *.tif

many instances outside of these conditions are rendered transparent. For example, if:

b1 = 0
b2 = 0
b3 = 15

Am I missing something in defining transparent/nodata values in QGIS or with gdal?

3 Answers

QGIS can handle this under the Layer Properties/Transparency.

Layer Properties / Transparency

Correct answer by i.reese on June 4, 2021

I took an orthophoto and warped it to have black slivers. In this state the new image is without nodata as can be verified with gdalinfo.

Band 1 Block=1000x2 Type=Byte, ColorInterp=Red
Band 2 Block=1000x2 Type=Byte, ColorInterp=Green
Band 3 Block=1000x2 Type=Byte, ColorInterp=Blue

Then I used your gdalbuildvrt command

gdalbuildvrt -srcnodata "0 0 0" out.vrt test.tif

The resulting .vrt file has now noData defined and gdalinfo reports it

Band 1 Block=128x128 Type=Byte, ColorInterp=Red
  NoData Value=0
Band 2 Block=128x128 Type=Byte, ColorInterp=Green
  NoData Value=0
Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
  NoData Value=0

This is how the warped image shows in QGIS with default settings on top of a green polygon

enter image description here

And this is how the VRT file with nodata opens in QGIS out-of-the-box

enter image description here

I can't see any issue with my test image. If you still have a problem it would be nice if you could provide us with test data.

Answered by user30184 on June 4, 2021

Here are two images representing what got us to questioning how nodata is read in QGIS.

enter image description here

When we defining the nodata of the image to "0" using QGIS, we were also making internal pixels transparent too. Even those regions that were not "0 0 0" are being rendered transparent.

enter image description here

I was only using QGIS as my testing space to be honest, but it was helping me understand how to solve the issue using MapnikXML; which we managed to do using a combination of:

gdalbuildvrt -srcnodata "0 0 0" welly.vrt *.tif

then rendering the individual rgb bands in Mapnik and adding them back together with:

raster-comp-op: plus;

Using CartoCSS, in order to achieve a similar outcome to the solution in QGIS seen above, the code looks something like:

#red 
{
  raster-opacity:1;
  raster-scaling:bilinear;
  raster-comp-op:plus;
  raster-colorizer-default-mode:linear;
  raster-colorizer-default-color: transparent;
  raster-colorizer-stops:
    stop(0,transparent, exact)
    stop(1,#000)
    stop(200,rgb(255,0,0))
}


#green 
{
  raster-opacity:1;
  raster-scaling:bilinear;
  raster-comp-op:plus;
  raster-colorizer-default-mode:linear;
  raster-colorizer-default-color: transparent;
  raster-colorizer-stops:
    stop(0,transparent, exact)
    stop(1,#000)
    stop(200,rgb(0,255,0))
}

#blue 
{
  raster-opacity:1;
  raster-scaling:bilinear;
  raster-comp-op:plus;
  raster-colorizer-default-mode:linear;
  raster-colorizer-default-color: transparent;
  raster-colorizer-stops:
    stop(0,transparent, exact)
    stop(1,#000)
    stop(200,rgb(0,0,255));
}

Answered by i.reese on June 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP