I am very new to GIS, QGIS and Python so please bear with me. I am using QGIS 2.0 and I would like to develop a QGIS plugin that would display the raster layers of the main window in order to allow for some specific interaction. I have a very hard time getting this to work! I generated the skeleton of my plugin through plugin builder, and changed the [moduleName]2dialog.py file to try to display the main window layers.
So I have two questions : 1/ Is it possible to get the layers? 2/ Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?
- Is it possible to get the layers?
- Can I draw it inside a GqsMapCanvas inside my plugin GUI, or do I need another object?
This is the code I have for now, which generates an error :
from PyQt4 import QtCore, QtGui
from qgis import core, gui, utils
from qgis.gui import QgsMapCanvasLayer
mc = iface.mapCanvas()
layers = mc.mapRenderer().layerSet()
if not layers:
self.ui.displayFileNameTextEdit.setText("No layer to display.")
else:
for layer in layers: #layer is one id
self.ui.qgsMapCanvas.setExtent(layer.extent())
self.ui.qgsMapCanvas.setLayerSet( [ QgsMapCanvasLayer(layer) ] )
self.ui.qgsMapCanvas.refresh()
Thank you very much! I'll appreciate any idea.