13

I have a number of layers in the Layers Panel inside a group but I don't want them shown (there's quite a lot so it looks untidy). These layers are also joined to several others.

Is it possible to make these layers invisible to the user (i.e. not shown in the Layers Panel, it is not about setting the visibility of the layer) but can still be joined to other layers? Or perhaps make the group invisible?

Closest I found was this post but hoping there's a more direct approach:

Showing only some layers in QGIS legend?

15
+100

I find making layers/groups 'invisible' useful to avoid showing lookup tables, which are required for value relations but might make the Layers Panel look a bit overloaded.

Just to clarify, invisible layers/groups will not appear in the Layers Panel, but they can still be seen in the canvas or used in joins/relations with other layers.


ANSWER:

Use the plugin Invisible layers and groups, which allows you to:

  • Make selected layers/groups invisible (plugin button).
  • Make layers/groups (that are invisible) visible again (plugin button).
  • Store layers/groups visibility in your QGIS project.
  • Recreate layers/groups visibility when opening your QGIS project.
  • Make a particular layer invisible (by code).
  • Make a particular group invisible (by code).

Making a layer invisible (by code):

if 'InvisibleLayersAndGroups' in qgis.utils.plugins:
    ilg = qgis.utils.plugins['InvisibleLayersAndGroups']
    ilg.hideLayer( layer )    # layer is a QgsMapLayer

Making a group invisible (by code):

if 'InvisibleLayersAndGroups' in qgis.utils.plugins:
    ilg = qgis.utils.plugins['InvisibleLayersAndGroups']
    ilg.hideGroup( group )    # group is a QgsLayerTreeGroup
    ilg.hideGroup( 'group2' ) # You can also pass a group name

Note: There is an issue you should be aware of. If you make a layer invisible and then move its parent group, the invisible layer will be visible again (I don't know why!). So, my recommendation is to make only top layers/groups invisible (after all, you cannot move the root).

  • Exactly what I was looking for, many thanks for this! Indeed, I have several layers which are used for calculations (all of which are joined to another layer) so I don't want the user to see or edit these layers. So your solution greatly solves this. One question, did you only implement this as a plugin recently? – Joseph Mar 6 '17 at 10:01
  • Right, it was published days ago. I had wondered how to hide layers before, but only after this question I undertook the task (I'll need this at work sooner or later). I thought of answering with code snippets but the answer was long enough to become complex, so I preferred to encapsulate it in a plugin, which is much easier to use. – Germán Carrillo Mar 6 '17 at 12:24
  • Well it's a great plugin so voted for it :) – Joseph Mar 7 '17 at 9:57
  • +1 A very useful plugin. Especially for my work, to be specific in mapping data in the field with a Tough Book + QGIS, to avoid an overloaded Layer Panel (scrolling takes time in the field). I have a suggestion (maybe to improve your plugin (or not)): Could you implement that the plugin remembers the layers you have marked once and make them invisible again when the plugin button (make them invisible) is pushed again? To set another selection (layers/groups) invisible you have to select them anew. – Stefan Jan 19 '18 at 13:39
  • Great that you find the plugin useful! Thanks for your suggestion, would you mind adding a new Feature Request (issue) in GitHub? – Germán Carrillo Jan 19 '18 at 20:32

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.