13

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
    Mar 6 '14 at 12:08
  • 1
    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
    Apr 26 '14 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
    Jul 31 '14 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
    Jul 31 '14 at 17:44
  • Maybe this answer will be helpful: gis.stackexchange.com/questions/41977/…
    – user7172
    Nov 14 '14 at 9:02
5

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
    Mar 24 '17 at 22:08
3

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

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.