Style management in context

“Creating a style once is fun, creating the same styles over and over is inefficient and boring. QGIS provides tools to manage, re-use and share your styles.”

In this module, we will look at how you can create re-usable styles in QGIS. We will also look at how you can make styles that will automatically be applied whenever a user adds a layer to a project. Once a style has been defined, it can be saved in a collection and given a name. That collection can be exported as a file which can be shared with other people.

You try:

Goal: Save styles to your style manager and exchange them with someone else.

Style manager:
Data: ne_10m_admin_0_countries from style-sharing/ne.sqlite and style-sharing/ne_10m_rivers_lake_centerlines.geojson

  • Load ne_10m_admin_0_countries layer into QGIS
  • Create a beautiful style for it
  • Save the style to your style library
  • Use the style manager to export your new style to an xml file
  • Send the xml style to a friend and get them to import it and apply it to a layer

Layer style:

  • Load ne_10m_rivers_lake_centerlines.geojson in QGIS
  • Create a beautiful style for it
  • Save the layer style definition as a qml file.
  • Send the qml style to a friend and get them to apply it to a layer

Check your results:

Use the table to compare behaviours between layer styles and the style library.

Layer Style Style Library
Layer scale
Expressions
Labels
Symbol levels
Other (note below)

More about

When styling layers, by default your styling work is saved only in the. QGS project file. You can permanently associate a style with a layer by using the 'save as default' option in the layer properties dialogue.

When saving styles that you intend to re-use with other layers, you should take care that the style does not use attributes from the layer that are unlikely to be in other layers (e.g. in expressions). For example, if you create a layer style that relies on an attribute called colour in an expression, that colour attribute should be in any other layer that you subsequently attempt to apply the style to. Take note of the following implementation details:

  • Symbol styles (saved in the style library) do not include label properties, layer scale dependent visibility, layer filters, layer variables etc. Symbol styles relate to only one symbol for a layer.
  • Layer styles (saved in QML files or in a database) do not include scale dependent visibility, layer filters, layer variables, but do include labelling options. Layer styles can include more than one symbol style within the style file.

It should be noted that both layer styles and symbol styles are saved in QGIS' own format which is not interchangeable with other software applications. You can also export your styles as SLD, but the fidelity to the original QGIS layer styling may not be good when using it in other software packages.

What if you want to share a whole collection of styles in your organisation? Check out the new Resource Sharing plugin.

Check your knowledge:

  1. If you want to share graduated, continuous or rule based symbology, which would you use:

    1. A symbol style exported as XML
    2. A layer style exported as QML
  2. What will happen if you export a polygon layer style and try to apply it to a point layer:

    1. QGIS will explode
    2. You will see an error message
    3. The layer style will be adapted to the new geometry type
    4. The layer style will be silently ignored

Further reading:

Download the sample data for the lesson.