[Qgis-developer] add rasterlayer to qgsmapcanvas

Felix Schmidt felix.schmidt at uni-weimar.de
Wed Jun 4 14:07:11 PDT 2014


Hello everyone,
I try to load on signal, a rasterlayer to qgsmapcanvas. I try it like in 
the pycookbook:

@QtCore.pyqtSlot()
     def loadRasterImage(self):
     print "slot works"
         fileName = QFileDialog.getOpenFileName(None, "historical map", 
".", "Image Files (*.png *.jpg *.bmp *.tiff)")
         fileInfo = QFileInfo(fileName)
         baseName = fileInfo.baseName()
         rlayer = QgsRasterLayer(fileName, baseName)
         if not rlayer.isValid():
             print "Layer failed to load!"
         QgsMapLayerRegistry.instance().addMapLayer(rlayer)
     print rlayer.extent().yMinimum()
     self.canvasRaster.setExtent(rlayer.extent())
     self.canvasRaster.setLayerSet( [ QgsMapCanvasLayer(rlayer) ] )

self.canvasRaster is defined in the gui . I search for 8h but I dont 
find a solutionen, because there are no errors.

It load the rasterlayer to the main program of qgis, but not in my 
qgsmapcanvas. it is still white.

please help me.

Felix


More information about the Qgis-developer mailing list