Styling in QGISStyle 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 DialogQGIS 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 | Applies 3D-like shading based on fixed height values or attribute value | Buildings | QGIS also generates full 3D views |
Apply StylingOpen 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 some 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
appropriate (or inappropriate) SVG image from the dialog, and change the size and colour to suit Do the same thing using Font Marker instead of
an 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 neighbourhoodsneighbourhood_ crime layer, using the total_crime attributecrimes layer Select Graduated from the dropdown Select total_all for the
value Value Click
classify Classify and review the results Change the setting of Mode, reclassify and see how this changes the visualisation
Sharing Labels and Reusing StylesThere 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 SLDQGIS 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 AnnotationsAny 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 LabelsIn 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 AnnotationsTurn 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
Sharing and Reusing StylesOnce 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 StylesZoom 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
QGIS and SLDQGIS 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. ImagesQGIS 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 LabelsLabels 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 F7In 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 AnnotationsAnnotations 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. |