I am quite new inthe field of GIS. I am interested in is to load the raster image which is in TIF format using QGIS API

I have followed the steps given the in the follwing link to load shape file enter link description here http://geospatialdesktop.com/2009/02/creating_a_standalone_gis_application_1/ and it works fine

To load the rester image i have followed the steps given int he link http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html

I have python 2.7.6 ,GDAL 1.10.1 installed with qgis2.0 installed in my system

code snippet

import osgeo.gdal
from  gdalconst import *
from PyQt4.QtCore import QFileInfo,QSettings
from qgis.core import QgsRasterLayer, QgsCoordinateReferenceSystem

file = QFileDialog.getOpenFileName(self, 
    "Open TIF Image", ".", "Tagged image (*.tif)")
fileInfo = QFileInfo(file)    
baseName = fileInfo.baseName()

layer = QgsRasterLayer(fileName, baseName)    

but the image is not loaded and i got the following error in the terminal

ERROR 4: `mypic.tif' does not exist in the file system,
and is not recognised as a supported dataset name.

Layer failed to load!
QObject::connect: Cannot connect (null)::repaintRequested() to QgsMapCanvas::refresh()
QObject::connect: Cannot connect (null)::screenUpdateRequested() to QgsMapCanvas::updateMap()

1 Answer 1


Change your last line to:

layer = QgsRasterLayer(file, baseName)

file contains the full path to your raster file (e.g., /home/user/geodata/mypic.tif), while fileName, which you are passing as argument right now, only contains the name of the file (e.g., mypic.tif).

  • gcarrilo i am new to the website and it requires atleast 15 points for upvoting so i am unable to do it Jan 28, 2015 at 10:28

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.