I'm using QGIS 3.0 model processor. I am trying to control the order in which the outputs render. Any ideas? I have tried to use parent algorithms but it seems to not make a difference. Is this a bug or an incorrect use of the parent algorithm function. Pictured are the outputs from my model. I want to have all the "A" files automatically draw on top of the others when the output from the model. enter image description here]

I've started trying to work with the code given by Kadir below and integrating it into the below hyperlink he provided. I have able to load in and work the example code. Now I am working on integrating Kadir's code into the model. I've included a snippet of the model below as well. https://anitagraser.com/2018/03/25/processing-script-template-for-qgis3/

enter image description here


1 Answer 1


To move layers whose name start with "A" to top of the layer tree, use that code.

root = QgsProject.instance().layerTreeRoot()
for layer in root.children():
    # you can change the condition
    if layer.name().startswith("A"):
        _layer = layer.clone()
        root.insertChildNode(0, _layer)

If you mean to order features in a layer, use "Order by Expression". To order features by area, use that: (smaller polygons stay behind)

enter image description here

  • So I tried the expression $area, but all my features are points and lines and therefore don't really have an "area." Is there a different expression I can give them? Apr 5, 2018 at 15:20
  • 1
    Do you want to control the order of layers or the order of features within one layer? Apr 5, 2018 at 15:25
  • I realized I was not being clear and I got pulled away before I edited my comment. Yes Kadir want to control the order of the layers. I am editing my post now. Apr 5, 2018 at 15:31
  • Kadir, do I incorporate this into the model by saving it as a script and adding it into my model? Does it matter which output it points to? Apr 5, 2018 at 16:50
  • 1
    Processing for QGIS 3 refer to Processing script template for QGIS3 Apr 5, 2018 at 18:22

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