4

from my Plugin I've loaded a rasterlayer using the following code:

fileName = "/path/to/raster/file.tif"
fileInfo = QFileInfo(fileName)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(fileName, baseName)
if rlayer.isValid():
    QgsMapLayerRegistry.instance().addMapLayer(rlayer)
    ...

Now I wonder how I can move the freshly loaded layer to the back, that it lies behind all previously loaded layers.

Thanks and regards

2

i have not come across to change layer order for taking an instance to back of all layers. But i think you can use addTopLevelItems(items) function for getting all layers to top without your current layer. Maybe it is a reverse solution but i hope it works for your needs.

PySide.QtGui.QTreeWidget.addTopLevelItems(items)

Parameters: items – PySide.QtGui.QTreeWidgetItem
Appends the items  as a top-level item in the widget.

Selecting current layer,

canvas = qgis.utils.iface.mapCanvas()
cLayer = canvas.currentLayer()

Or all layers,

allLayers = canvas.layers()
for i in allLayers: print i

i hope it helps you....

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.