I am using the QGis libraries in a external Qt App. When adding vector and raster layers (in any order) to the QgsMapLayerRegistry instance, it somehow sorts the layers so that the vector layers is first in the QgsMapLayerRegistry.mMapLayers list and then the raster layers. Which make perfectly sense otherwise at render time you wont see the vector layers if the order was the other way round.

But when adding a vector point layer with a memory data provider, i would like the layer to be first in the list, or at least "sorted" with the other vector layers. But is always end up last in the QgsMapLayerRegistry.mMapLayers list, and at render time it always gets rendered "beneath" the raster layer, how can i add the vector point layer with the memory data model, to be rendered "on top" of all other layers?

1 Answer 1


QgsMapLayerRegistry::mapLayers() doesn't affect the rendering order of the layers in the map. What you need to do is set the order in QgsMapCanvas::setLayerSet()

So something like this:

vector = QgsMapCanvasLayer(somevectorlayer)
memorylayer = QgsMapCanvasLayer(yourmemlayer)
raster = QgsMapCanvasLayer(yourrasterlayer)

QgsMapCanvas::setLayerSet([raster, vector, memorylayer])

The layer set is rendered bottom up.

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.