I have successfully loaded a TIF image (using raster2pgsql) into my PostGIS 2.0.1 database. I can load the raster image into QGIS and it displays in the correct space. However, it has lost all colour and appears as a greyscale image. (Layer Properties > Style > Single band gray, colormap = grayscale)

If I load the same image directly from file into QGIS it displays colours correctly.(Layer Properties > Style > Single band gray, colormap = colormap)

If I convert the TIF to JPG and load the JPG to PostGIS and then display in QGIS the colours render correctly. (Layer Properties > Style > Three band color)

I can save the colourmap from an image and apply it to the greyscale images but the colours aren't quite right.

What do I need to do to get the TIF images to retain their colourmap when I load to PostGIS?

Windows 7 32-bit PostgreSQL 9.1.4 PostGIS 2.0.1 QGIS 1.8.0 raster2pgsql -s 27700 -I -C -M *.tif -F -t 200x200 gis_rasters.osvmd > vmd.sql

Thanks in advance


  • Just some constructive criticism to help the site work at its best potential. Instead of editing the title to say "solved", you should mark the answer as accepted. This increases reputation for you and nhopton (as the person with the accepted answer), and also increases the likelihood of getting good answers to other questions you may ask. The list of questions notes which ones have accepted answers, meaning no need for "solved" in the title. Thanks. – user3461 Jul 23 '12 at 19:37

I suspect that your TIFFs might be Ordnance Survey Vector Map District rasters? I've not loaded any of these into Postgres/PostGIS but I have loaded some into a Rasterlite DB. The secret is to batch translate the TIFFs from indexed to RGB GeoTIFFs before loading them into the database. Raster -> Conversion -> Translate (Convert Format), tick 'Batch mode' and also tick 'Expand' (select 'RGB' from the drop down list).


  • Thanks Nick. Just the ticket. Batch converted a sample of the OS VMD rasters and loaded into PostGIS. Rasters display correctly in full colour. – mixedbredie Jul 23 '12 at 13:43
  • Thanks Nick, had the same issue and your solution works. It looks like there a new option in QGIS menus Raster > Convert > PCT to RGB which also work in Batch Mode and only does the color conversion Fabien – fnicollet Aug 7 '12 at 12:26
  • is there linux commandline for this? I have Windows desktop and linux server – simpleuser001 Nov 29 '12 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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