I am unable to load a PostGIS raster layer into QGIS. I have looked through previous posts Loading raster from PostGIS DB into QGIS and Cannot add the PostGIS raster layer with QGIS but was not able to solve the problem.

I tried both on QGIS Lisboa 1.8.0 and QGIS Dufour 2.0.1. In the Lisboa version I installed the plugin "Load PostGIS Raster to QGIS" 0.5.4 but I get the following error

An error has occurred while executing Python code:

Traceback (most recent call last):
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\wktRasterPlugin.py", line 90, in callAddLayer
    dlg = DlgAddRasterLayer()
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\DlgAddRasterLayer.py", line 40, in __init__
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\DlgAddRasterLayer.py", line 109, in updateUIMode
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\DlgAddRasterLayer.py", line 57, in listTables
    tables=conn.listTables(self,connstring) #returns a list of pairs (index, value)
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\conn.py", line 76, in listTables
    db = GeoDB(host=parmlist[2].split("=")[1],dbname=parmlist[1].split("=")[1],user=parmlist[3].split("=")[1],passwd=parmlist[4].split("=")[1],port=int(parmlist[5].split("=")[1]))
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\postgis_utils.py", line 134, in __init__
    raise DbError(e)
  File "C:/Users/Esteban/.qgis//python/plugins\wktraster\postgis_utils.py", line 83, in __init__
    self.msg = unicode( error.args[0], 'utf-8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 23: invalid continuation byte

Python version:
2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]

QGIS version:
1.8.0-Lisboa Lisboa, 6416f38

Python path: ['C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python', 'C:/Users/Esteban/.qgis//python', 'C:/Users/Esteban/.qgis//python/plugins', 'C:/PROGRA~2/Quantum GIS Lisboa/apps/qgis/./python/plugins', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\bin\\python27.zip', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\DLLs', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\plat-win', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\lib-tk', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\qgis\\bin', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\PIL', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\win32', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode', 'C:\\PROGRA~2\\Quantum GIS Lisboa\\apps\\qgis\\python\\plugins\\fTools\\tools']

How to solve the above problem in Lisboa version ?

Is it possible to load a PostGIS raster layer into the Dufour version ?

  • You are getting a UnicodeDecodeError, which points to a possible problem with the encoding of your data. Is by any chance your Postgres database is not encoded in UTF8?
    – cengel
    Nov 3 '13 at 18:36
  • Indeed, when I removed one database connection the error disappeared. But nevertheless, I am still unable to show rasters on QGIS. When I use through the menu Database/Database Manager -> right click on the raster/Add to QGis canvas nothing happens. When I use Database/PostGis Raster/Add a Postgis Raster Layer and I choose the raster I receive the message "Could not load PG: dbname= <db> host= <host> user= <user> password= <pw> port= 5432 schema= public table=<table> mode = 2". Someone has an example raster that works that I can use for test in order to determine the problem? Nov 4 '13 at 9:21

An interesting alternative is actually the DB Manager. You can try: Database > DB Manager > DB Manager. From there, navigate to the raster you want to load, and then either drag and drop it to the list of layers, or left-click and 'Add to canvas'.

More information, here.

  • Works like a charm on QGIS 2.4
    – bennos
    Jul 9 '14 at 15:13
  • 3
    Indeed. In my case, the pgraster isn't accessible from the browser window (which only shows vector layers). It's only accessible from DB Manager.
    – tinlyx
    Nov 24 '14 at 19:24

I got the same problem until I noticed that the appearing dialog is asking for the database user name (typical "postgres"). I always entered the password of my database. :-( Then everything worked as expected. (using QGIS 1.8)

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.