15

I am working on a big GIS project and not being able to sort the items in the Layers panel is giving me hard time. I can have up to 250 layers in the Layers panel.

I have a special naming scheme for all the TIFF raster files I import and geo-reference in QGIS. But when I import them I can't import them one by one in alphabetical order, because my co-workers are working on some of the files and I am working on others. So the items in the Layers panel are all over the place. The program is not intelligent enough to sort them in alphabetical order. Instead it sorts them in the order I import them.

Here, take a look at this screenshot.

a

Is there no built-in option in QGIS that would allow me to sort these items? If not, is there a plugin I can install that would allow me to do this?

Edit: I found this and the first few lines of code seem to do the trick.

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.utils import iface

mw = iface.mainWindow()
lgd = mw.findChild(QTreeWidget, "theMapLegend")  # get ref to object by type/objectName
lgd.sortItems(0, Qt.AscendingOrder)  # sort first column (Qt.DescendingOrder to reverse)

But I'm not a fluent C++ or a Python programmer. Seriously?... Do I have to pick up a programming cook book to sort the layers in QGIS? Could it be any more difficult?...

b

Is there no plugin that can do the same job? I'm afraid to use code that I don't understand on an important project.

6
  • 1
    To judge by what I have read on the QGIS website this has been a requested feature for a few years now. All the "solutions" I have found so far involve using blocks of code to get things done. I installed QGIS 2.2.0 which was released last month and it has no such option for sorting layers. Since this is not a priority, it would be very nice if someone could write a plugin to add this feature to QGIS.
    – Samir
    Commented Mar 6, 2014 at 12:08
  • 2
    If the project is important, take a backup and try the code. You would rather trust a plugin which you don't understand either? I don't think that makes sense.
    – underdark
    Commented Apr 26, 2014 at 21:45
  • @underdark For someone without any programming skills this might be an obstacle. "Find and pay someone writing a plugin for that" would be a better answer. I think we should establish a kind of QGIS developer market platform for such issues. Or have we already?
    – AndreJ
    Commented Jul 31, 2014 at 6:08
  • @AndreJoost currently there is only the list of commercial support/dev providers on qgis.org. The best place to get in touch is on the dev mailing list.
    – underdark
    Commented Jul 31, 2014 at 17:44
  • Maybe this answer will be helpful: gis.stackexchange.com/questions/41977/…
    – user7172
    Commented Nov 14, 2014 at 9:02

3 Answers 3

8

You can use a plugin i wrote, see https://plugins.qgis.org/plugins/SortLayers/

This plugin arranges alphabetically all layers in the Layers Panel (from A to Z, or from Z to A).

You use it by pressing a button.

1
  • Please edit your answer to provide some information about what your plugin does, how to use it, and what it does to answer the question.
    – Midavalo
    Commented Mar 24, 2017 at 22:08
5

There is an open feature request for this function: http://hub.qgis.org/issues/6828

4

https://plugins.qgis.org/plugins/layer_tree_tools/

This is a plugin that can sort the layers by name (from A to Z or Z to A) and also by: geometry, position (extent), file size, storage type, encoding, time of modification...

... as well as group the layers that share a same property of one of the above.

Sorting/grouping can be applied across the whole tree or within certain groups only or in root only.

Everything is available through its GUI and it also gives you an icon in the Layers Panel for quick access, but you can call it from the Plugins Toolbar as well.

If you want to call it from your Python code, you can do it by importing its sorter.py module (or grouper.py if you want to group) in your code and call its functions.

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.