Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Numberedheadings
h3, h4start-numbering-with
number-formatdecimal
skip-headingsHNaN
start-numbering-with3
h1[h1.decimal].3
h2[h1.decimal].[h2.upper-latin]
h3
h4
h5
enabledtrue
h6
start-numbering-atH1

Styling in QGIS

Style needs to be added to data to give it a useful visualisation on the map. Styles can be very simple (for example 'colour everything blue'), or more complex, with multiple rules and elements. This module covers some basic styling approaches and techniques, with pointers to more advanced techniques.

The Style Dialog

QGIS applies a random style to every layer when it is loaded (otherwise layers would not be visible). Set your own style using the Symbology tab in the Layer Properties dialog.

The table below lists the main style types QGIS supports - this course will cover those highlighted. Some styles are only available for certain geometry types.

Symbology type

Geometry

Description

Example

Comment

No symbols

All

The layer will not appear on the map.

Display the data using labels only


Single symbol

All

The same symbology will be used for all features

Location of villages

Symbol can be sized proportionately to an attribute value - for example population

Categorized

All

A different symbology will be used for each unique value of an attribute

Crime types

Depending on values, each feature could have a unique style, or features could share the same style

Graduated

All

For numeric data only, values can be 'banded', with each band having a different style, usually using a graduated colour ramp

Voting patterns

Number, size and statistical composition of bands can be set by user

Rule-based

All

One or more rules can be used to determine styling

Ordnance Survey MasterMap

Used to apply more complex logic to styling, for example where the content of more than one attribute is used to determine style

Point displacement

Point

Move points slightly if they are in the same location, or within a set tolerance of each other, so that they are all visible

Crime locations

Where representation of numbers is more important than geographical accuracy

Point cluster

Point

Coalesces points which are in the same location or within a set tolerance of each other into a single symbol, with a number showing the count of the points included

Crime locations

Where representation of numbers and geographical accuracy to a certain zoom level is required, with numbers of points coalesced changing with zoom level

Heat map

Point

Continuous surface of varying colour and intensity based on point density

Bird nesting locations

Best used to visualise point locations over an homogenous area

Inverted PolygonsPolygons

Polygon

Applies any styling inside the polygon to areas outside the polygon instead

Feathered border

Can be used to apply focus to polygons

2.5 D

PolygonsPolygon

Applices Applies 3D-like shading based on fixed height values or attribute value

Buildings

QGIS also generates full 3D views

Apply Styling

  1. Open essentials_03_styling.qgz and save it with a new name

  2. Create a Single Symbol style for the canal_crt layer

    1. Double-click on the layer, and go to the Symbology tab

    2. Click on Simple Line to amend the properties of the existing style

    3. Choose one of the styles in the lower part of the dialog and make some amendments to

come
    1. some of the style components (click on the Favorites dropdown above the symbols and change the setting to All Symbols to see more options)

    2. Click Apply to see the effect of your changes without closing the dialog

    3. Click OK when done

  1. Create a Single symbol style for the wind_turbines_point layer, using an SVG or Font marker

    1. Go to Symbology for the layer

    2. Click on Simple Marker, and change the Symbol Layer Type below it to SVG Marker

    3. Select an

appropriate (or inappropriate)
    1. SVG image from the dialog, and change the size and colour to suit

    2. Do the same thing using Font Marker instead of

an
    1. SVG Marker (choose a font such as Wingdings or Webdings)

  1. Create a Categorized style for the osmm data using the theme attribute

    1. In Symbology, choose Categorized from the dropdown at the top, and set Value to theme

    2. Click Classify at the bottom of the dialog to set the colours

    3. Double-click on the symbol for each value to change its style

  2. Apply a Single Symbol style to aonb_wales, with some transparency or hatching so that the base layer can be seen behind it

  3. Create appropriate symbols and name labels for the railway_naptan layer

  4. Create a Graduated style for the

surrey
  1. neighbourhood_

neighbourhoods_crime layer, using the _burglary attribute

10.3.2. Styling the Map

  1. Create a Single symbol style for the canal_crt layer- use and amend one of the QGIS styles, or create your own from scratch

  2. Create a Single symbol style for the wind_turbines_point layer, using an SVG or Font marker

  3. Create a Categorized style for the osmm data using the theme attribute

  4. Apply a Single symbol style to aonb_wales, with some transparency or hatching so that the base layer can be seen

  5. Create symbols and name labels for the railway_naptan layer

  6. Create a Graduated style for the surrey_neighbourhoods_crime layer, using the _burglary attribute

You can edit the individual class styles:

  • Right-click on one of the styles to get a limited set of options (e.g. colour, size, opacity)

  • Double-click to see the full style dialog

You can also double-click on the text under the Legend heading to change it.

Graduated

Graduated styling requires numeric attribute values, and places them within ranges, each of which will be styled differently. The example below uses neighbourhood crime data, showing the number of vehicle crimes in one month per neighbourhood.

To apply a graduated style:

  • Select Graduated from the dropdown list

  • Under Column, select the field with the relevant data that you want to represent

  • Click Classify to create the class bands and apply the Color ramp

  • Adjust the settings and click Classify again if required

    Re-using Styles

    There are a number of ways to re-use a style. You can:

    • Copy/paste styles between layers: select the layer, right-click > Copy (or Paste)

    • Save a style in the QGIS native file format, .qml, for importing to another project: double-click the layer > Layer Properties > Symbology > Style > Save Style > QGIS Layer Style File

    • Save a style as an SLD (Styled Layer Descriptor), for use in other applications which support it: double-click the layer > Layer Properties > Symbology > Style > Save Style > SLD File

    • Load a style from QML or SLD: double-click the layer > Layer Properties > Symbology > Style > Load Style

    QGIS and SLD

    QGIS does not yet support all of the SLD standard in its export and import - there are some styles which will not be translated. You may also need to do some tweaking of the SLD file (which is in XML), depending on the application you are working with.

  • Create and import style libraries (groups of styles) for example for corporate use: Settings > Style Manager > Import / export

  • Set a style as a default, to be used when a layer is added to a project. This works well if the layers are stored in a PostGreSQL database, as the default styles are available to any user. File-based default styles are normally only be available to the local user: double-click the layer > Layer Properties > Symbology > Style > Load Style > Save as default 
    1. crimes layer

      1. Select Graduated from the dropdown

      2. Select total_all for the Value

      3. Click Classify and review the results

      4. Change the setting of Mode, reclassify and see how this changes the visualisation

    Labels and Annotations

    Any data in the attribute table can be added to the layer as a label, and labels can contain expressions - for example to include data from multiple columns. You can also add, format and position individual labels using Annotations.

    Add Labels

    1. In the properties for railway_naptan, go to the Labels tab and select Single Labels from the dropdown

    2. Set the Value to StationName and click Apply at the bottom of the dialog to see the effect

    3. Change the Font settings under Text in the lower part of the dialog to make the labels more prominent

    4. Add a Buffer to the labels to make them stand out against a darker background

    5. Look at the Placement and Rendering settings, make some changes and see what the effects are

    Annotations are standalone labels which can be formatted in a number of ways to suit your requirements. They need to be created, formatted and positioned individually - this takes more time, but gives more control over the end result.

    Add Annotations

    1. Turn on the Annotations toolbar

    2. Click on Text Annotation (the button far right)

    3. Click on the map to add the annotation

    4. Click and drag the red marker to move the geographical anchor point of the annotation, and click and drag the annotation box to position it

    5. Double-click on the annotation box to add content and formatting

    6. Add some content, and change the Frame style and Map marker

    7. Add and format more annotations if you have time

    Sharing and Reusing Styles

    Once you have created a style, you can re-use or share it in a number of ways, and you can also load styles created by others. This example covers the use of a ready-made style - for this you are going to use OS MasterMap, and load a saved style from a qml file.

    Reusing Styles

    1. Zoom to the extent of the osmm layer - the sample covers the city of Exeter

    2. Go to Symbology for the layer, then Style > Load style and navigate to ../QGIS Training/Data/styles/osmm_topo_area.qml

    3. Click Load Style then OK to load the Ordnance Survey QML style file and apply it to the data

    4. Have a look at the style, and how it is constructed - this one is Rule-based

    5. Open the railwayline layer from the vector folder and zoom to it

    6. Right-click on the canals_crt layer, then Style > Copy Styles > All Style Categories

    7. Right click on railwayline, then Style > Paste Styles > All Style Categories - this will copy the style you created for canals to the railway lines layer

    8. In the Symbology tab for railwayline, click Style (at the bottom), then Save Style - this dialogue will save the style as a QML file for use later, or for sharing with others

    QGIS and SLD

    QGIS can export to Styled Layer Descriptor (SLD) format, although not all styles are supported. SLD is an OGC standard which is supported by a number of applications, including Astun’s iShare.

    Images

    QGIS uses Scalable Vector Graphic (SVG) images as its native image format - other formats such as PNG and JPG can only be used if they are embedded in a SVG file. Graphics programs such as InkScape can be used to create SVG images. Images can be used in all geometry types - for point styles, for area fills, and for markers on a line.  SVG images can be coloured and scaled, and combined to create composite images, so they are more versatile than some other formats.

    To use an SVG image:

    In the Symbol Selector dialog (where a specific symbol is configured), from the Symbol Layer Type dropdown list select SVG marker
  • Select the SVG marker to use from the library, or use the file manager view to browse to your own SVG image

  • Adjust the settings such as size and colour to suit your needs

  • Labels

    Labels are also configured from the Layer Styling dialog (the Style Dock). To activate the labels dialog:

    Click the button at the top of the Layers panel , or hit F7
  • In the Labels dropdown, select Single Labels

  • In Value, select the column to be used for labels

    You can now adjust a range of settings for labels, including font, placement and formatting. 

    Here are a few pointers and tips:

    If some labels are not appearing on the map, this may be because they are conflicting with other labels and so have been removed. Use Show all labels for this layer in the Rendering tab 

     so you can see all labels

    Use the settings in the Buffer tab

     to draw a buffer or halo round labels so they stand out against a darker background 

    Use the Expression Builder button 

     (next to the Label with field) to build labels with expressions - for example concatenating two or more attribute values, or creating a total of numeric values

    Annotations

    Annotations provide a means of adding labels or images to a map which independent of the data. The formatting is flexible, so while by default they look like callouts, they can also be made to look like labels.
    Create annotations by clicking the Text Annotation button in the Attributes toolbar - once this is activated, every time you click on the map canvas, an annotation will be created. Double-click an annotation to edit its properties: text, style, frame, marker etc.