3. 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.
3.1. 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 Polygons | 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 | Polygon | Applies 3D-like shading based on fixed height values or attribute value | Buildings | QGIS also generates full 3D views |
3.1.1. Apply Styling
Open essentials_03_styling.qgz and save it with a new name
Create a Single Symbol style for the canal_crt layer
Double-click on the layer, and go to the Symbology tab
Click on Simple Line to amend the properties of the existing style
Choose one of the styles in the lower part of the dialog and make some amendments to come of the style components (click on the Favorites dropdown above the symbols and change the setting to All Symbols to see more options)
Click Apply to see the effect of your changes without closing the dialog
Click OK when done
Create a Single symbol style for the wind_turbines_point layer, using an SVG or Font marker
Go to Symbology for the layer
Click on Simple Marker, and change the Symbol Layer Type below it to SVG Marker
Select an SVG image from the dialog, and change the size and colour to suit
Do the same thing using Font Marker instead of SVG Marker (choose a font such as Wingdings or Webdings)
Create a Categorized style for the osmm data using the theme attribute
In Symbology, choose Categorized from the dropdown at the top, and set Value to theme
Click Classify at the bottom of the dialog to set the colours
Double-click on the symbol for each value to change its style
Apply a Single Symbol style to aonb_wales, with some transparency or hatching so that the base layer can be seen behind it
Create appropriate symbols and name labels for the railway_naptan layer
Create a Graduated style for the neighbourhood_crimes layer
Select Graduated from the dropdown
Select total_all for the Value
Click Classify and review the results
Change the setting of Mode, reclassify and see how this changes the visualisation
3.2. 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
In the properties for railway_naptan, go to the Labels tab and select Single Labels from the dropdown
Set the Value to StationName and click Apply at the bottom of the dialog to see the effect
Change the Font settings under Text in the lower part of the dialog to make the labels more prominent
Add a Buffer to the labels to make them stand out against a darker background
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
Turn on the Annotations toolbar
Click on Text Annotation (the button far right)
Click on the map to add the annotation
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
Double-click on the annotation box to add content and formatting
Add some content, and change the Frame style and Map marker
Add and format more annotations if you have time
3.3. Sharing and Reusing Styles
Once you have created a style, you can re-use or share it on 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
Zoom to the extent of the osmm layer - the sample covers the city of Exeter
Go to Symbology for the layer, then Style > Load style and navigate to ../QGIS Training/Data/styles/osmm_topo_area.qml
Click Load Style then OK to load the Ordnance Survey QML style file and apply it to the data
Have a look at the style, and how it is constructed - this one is Rule-based
Open the railwayline layer from the vector folder and zoom to it
Right-click on the canals_crt layer, then Style > Copy Styles > All Style Categories
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
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
3.4. 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.
3.5. 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.