0

I have a set of 14 rasters that I would like to create a virtual raster (vrt) from. When I create the vrt one of the rasters does not appear in the new file. The raster have identical formats except the missing one displays Band 1 (Gray) in the layer styling box and the others show Band 1 (Palette). It seems like this is due to the missing one not having a color table or palette where as the others do. I have gotten around this by creating a vrt of the tif without the color palette, opening the vrt with a text editor and changing <ColorInterp>Gray</ColorInterp> to <ColorInterp>Palette</ColorInterp> and then creating a vrt with the other 13 and the hacked vrt.

Is there a way I could instead convert the file to have a color table or better remove the color table from the others? From my tests warp does not strip the color table.

3 Answers 3

2

Inside QGIS you can use Raster-> Conversion -> PCT to RGB, or you can use the GDAL Utility pct2rgb to convert the palette to a rgb image.

1
  • Sorry I couldn't test this. I couldn't get that to work with my file. I get a AttributeError: 'NoneType' object has no attribute 'GetCount' error. I want to end up with a single band file wouldn't this give me a 3 band file?
    – Baswein
    Jan 9, 2020 at 17:30
1

You may be able to remove the palette with gdal_translate https://gdal.org/programs/gdal_translate.html by using the option -expand gray. Try and tell if it works, the documentation is a bit cryptical.

-expand gray|rgb|rgba

To expose a dataset with 1 band with a color table as a dataset with 3 (RGB) or 4 (RGBA) bands. Useful for output drivers such as JPEG, JPEG2000, MrSID, ECW that don’t support color indexed datasets. The ‘gray’ value enables to expand a dataset with a color table that only contains gray levels to a gray indexed dataset.

1
  • It seems the QGIS 3.8 dialog for Translate does not have the ability to add additional command line options so I was unable to try this.
    – Baswein
    Jan 9, 2020 at 17:33
1

The way I solved this was by running GDAL merge with only one file and Grab pseudocolor table from first layer unchecked. This gets rid of the color table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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