7

Is there a way to get QGIS3 to automatically apply specific symbology based on the layers name for example?

My situation: I digitize maps often based off satellite imagery. I draw the map using one set of symbology, when I wish to produce the final map I must manually go through each layer and change the symbology for the output map. This is extremely tedious and quite often there is small variations between maps, as each time I set the symbology it is not exactly the same as last time.

I have started saving styles and loading them up for each layer which is an improvement, but I still have to go through each individual layer and load the style. I often have hundreds of layers.

Each layer has different symbology.

4

You can try use Set style for vector layer algorythm.

enter image description here

Adventage of that solution is that you can make it batch processing/save that to for later reuse.

  • This works, exactly what I was looking for. – user5505559 Oct 30 at 3:56
5

Multi-layer style copying/pasting

If all or most of the layers you want to style share the same symbology, you can:

  1. Apply a pre-saved style to one layer by loading a style from file
  2. Right-click on the layer in the layer list, select Styles->Copy style->All style categories
  3. Always in the layer list select all the layers you want to apply the same style to, then Styles->Paste style->All style categories
  • 1
    Style copying/pasting is amazing, there are a lot of clicks involved for the amount of it I do so I have set it to CTRL+SHIFT+C and CTRL+SHIFT+V. – TeddyTedTed Oct 25 at 7:56
  • If it is an operation you need to perform frequently, using a keyboard shortcut like ctrl+shift+c / v makes definitely sense! – RafDouglas Oct 25 at 8:34
4

I think what you are looking for are Map themes. You can access map theme manager by clicking an eye symbol, in the upper icons row, in layers panel. Then simply choose 'add theme'. All the styling and visibility settings for layers, in the layer panel list, will be saved, a new entry will appear in the theme list. You can also use named Map themes to style Maps in layouts by one click. Here is the link to documentation section: https://docs.qgis.org/3.4/en/docs/user_manual/introduction/general_tools.html#configuring-map-themes

Besides visibility, map theme will also store layer's symbology, but you have to save it as named style first. enter image description here To do so, right-click on the layer's row in legend panel, than choose styles>Add, you have to name the current style. Confirm and you will see it on the list above color picking wheel. Afterwards you can change the layer's symbology and save the new configuration in the same way. When there is more than one style on the list, you can switch symbology by picking the right entry by name.

When you will define a new map theme it will store current visibility settings as well as currently active named style.

  • Doesn't this method simply save various combinations of layers being turned on and off? I can't seem to get it to change the actual symbology within the layers, which is what I want to do. – user5505559 Oct 30 at 0:36
  • 1
    I have edited the answer, use named styles to make it change symbology. – Michal Nov 13 at 9:35
2

I think I've figured something out but it would take a bit of an investment of time to set it up. It involves creating what's basically a lookup table for symbology.

Building the Table

Add a table to QGIS with no geometry, just an attribute table (for this example I will call it 'symbology_table').

Fields it will need (for example):

FieldName    DataType   Format        Description
layer        string     exact match   name of the layer used to look up symbology
stroke_col   string     0,0,0,0       colour of stroke in RGBA format (r,b,g,alpha 0-255)
stroke_lw    real       0.00          lineweight of the stroke
fill_col     string     0,0,0,0       colour of fill in RGBA format (r,b,g,alpha 0-255)

Populate this with table with the names of the layers you want automatically styled and their corresponding style values. For example I want one layer called Study Area to have a red outline and a transparent red fill, and another layer called Site with a blue outline and fill I would add them to the table like this:

layer         stroke_col     stroke_lw    fill_col
study area    255,0,0,255    0.5          255,0,0,100
site          0,0,255,255    0.5          0,0,255,100

Setting up the layers

Open the symbology of one of the layers and set the Fill color to this expression:

ATTRIBUTE(GET_FEATURE('symbology_table', 'layer', @layer_name), 'fill_col')

set the Stroke color to this:

ATTRIBUTE(GET_FEATURE('symbology_table', 'layer', @layer_name), 'stroke_col')

and the Stroke width to:

ATTRIBUTE(GET_FEATURE('symbology_table', 'layer', @layer_name), 'stroke_lw')

Now using the trusty Multi-layer style copying/pasting mentioned by @RafDouglas you can apply this styling to every single layer and as long as it has a value in the symbology_table it will take on it's own symbology.

Notes

  • This won't update the symbols in the table of contents.
  • You can add as many symbology fields as you want to the symbology_table, I just used those generic ones as an example.
  • This example was for setting the symbology of polygon layers, for point and line layers the theory is the same but it may need slight tweaking.
0

QGIS can automatically apply styles based on layer names. The process that I use involves categorized styles which are applied to GeoPackage layers. This way you can create your categorized style set with layer names and values once and apply these to any layer which contains the same names.

If you are using GeoPackage and your initial styles are different to those that you wish to apply for your final map, I would consider creating separate styles for each. You may need to add an additional attribute field to use to set your styles (as appropriate).

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.