Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.