Our training courses are structured to give trainees step-by-step guide using the latest QGIS features. Here is an example of one our practicals for creating professional maps.
Trainees will learn how to
QGIS' Print Composer allows users to create professional maps forprinting. It supports legends, frames, logos and all the other featuresyou'd expect to see in a print quality map.
In this example, we'll use some of the most common features required togenerate a map for printing.
We'll first load the electricity usage data created inanother tutorial, style it using a simple colour ramp, thencreate a new map composer complete with title and legend.
The styling of a vector layer can be performed using a single style, ora varying style, based on the value of one or more attributes. We aregoing to first load the London energy usage layer prepared inan another tutorial by joining electricity usage with the LSOAs vector layer.
Start a new QGIS project
Add the MSOA_GL_ElecUsage.shp layer under extracted
downloaded folder
The vector layer should now look like the figure below.
Next, we are going to add a shapefile of London Boroughs to identifyareas of high and low usage.
Add London_boroughs.shp from extracted downloaded
folder
Open layer properties and under Style:
Set the style of the polygons to "No Brush" with a
"Dash Line".
Your map now should look like the figure below:
Energy consumption in London
In QGIS, you can apply multiple styles to a single layer. Using thismethod, we do not need to load the same layer multiple times. In thiscase, we need two styles for London boroughs layer:
We can save the current style (without label):
Right-click on London_boroughs layer from the layer
tree and select Styles > Add
For the new style, type 'no label' and click OK
We can save the new styles (with labels) for the layer:
Right-click on London_boroughs layer from the layer
tree and select Styles > Add
For the new style, type 'with label' and click OK
Changes in the next section (adding label) will be saved in withlabel style.
We'll now add labels to each of the boroughs. The name of each boroughis stored as the value of the NAME attribute.
Click on the London_boroughs layer in the ToC
Form the main menu, select Layer > Labelling
This window will allow us the set an attribute for label and also change font, size, rotation, buffer, etc.
Enable the Label this layer with option
Set Field with labels to NAME
Under Text section, set the font to 7 pt
Under Buffer section:
Enable Draw text buffer
Set the Size to 0.5 mm
Click OK
You should now be able to see a label for each borough.
In QGIS, you can create presets for layer visibility and styles. In thisexample we are going to create the following presets:
To create the first preset:
Ensure both layers are visible
Right-click on London_boroughs and select
Style > with label
On top of the legend tree in QGIS, you can see the icon for ManageLayer Visibility
Click on the Manage Layer Visibility icon
From the drop-down menu, select Add preset...
For the Name of the new preset insert Energy map
Click OK
To ensure the preset has been correctly set, you can change thevisibility of the layer, or change the style, and select the preset fromthe Manage Layer Visibility menu.
To create the second preset:
Hide All Layers from Manage Layer Visibility or simply
press Ctrl+Shift+H
Turn on the visibility for London_boroughs
Right-click on London_boroughs and select
Style > no label
On top of the legend tree in QGIS, click on
Manage Layer Visibility
From the drop-down menu, select Add preset...
For the Name of the new preset insert overview map
Now you should be able to switch between those two presets, and lateruse them as print composer frames.
The map is almost ready to be printed. Before printing, we'll need toadd a border, logos, legends, scale, etc.
There are quite a few steps involved in configuring the print composerso it's recommended to regularly save your progress by saving the QGISproject.
From the main menu, select File > New Print Composer
A new window will appear for Composer title
Type Energy usage in London
The print composer title window
The print composer will appear. See Figure.
The print composer window
The print composer is split into two sections. Section 1 shows the mapto be outputted and section 2 shows the settings for selected items insection 1.
The map we are going to produce is an A4 landscape PNG file.
In section 2, under Composition, for Presets, select
A4(210 x 297 mm)
Now we need to add frames for the map extent and legend sections. You can add a rectangular shape by clicking on
from the main toolbar.
From the main toolbar, add a new rectangle
Click and drag a shape in section 1
Now let's change the position and size of the rectangle:
Ensure the rectangle shape is selected in section 1
Click on Item properties in section 2
Under Shape, select Position and size
Set the option as shown in Figure
Add second, third and fourth rectangles with the
following information
Rectangle 2:
X: 270
Y: 145
Width: 43.5
Height: 60
Reference Point: Centre
Rectangle 3:
X: 270
Y: 95
Width: 43.5
Height: 60
Reference Point: Centre
Rectangle 4:
X: 270
Y: 105
Width: 43.5
Height: 200
Reference Point: Centre
Lock the position of each window by right-clicking
on each of them
Section 1 of the print composer should look like this:
Let's add the logos.
From the main menu, select Layout > Add Image
Click within the middle rectangle on the right
An empty box will appear
In the right-hand panel (section 2), under the
Item properties tab,
click on Main properties button
For Path, click on ... and browse to the folder where
your images are located.
Select an image
You should now see something similar to the image below.
Now we'll add some text in the rectangle below the logos:
From the main menu, select Layout > Add Label
Click somewhere within the lower right-hand box
A new text box will appear, reading QGIS.
From the right-hand panel, click on Item properties
In Main properties, change the text to refer to the
source of the data and copyright notices.
Now we'll add the map from the QGIS canvas.
From the main menu, select Layout > Add map
Drag a box in the main window
A map similar to the image below should now appear in theprint composer.
To finalise the main map window, a few more changes will need to bemade.
From the right panel, click on the Item properties tab
Under the Main properties, set the following values:
Tick the box for Lock layers for map item see
image below
Under Extents:
Tick the box for Controlled by atlas
To add a scalebar:
From the main menu, select Layout > Add Scalebar
A scalebar with default settings should appear on the map. See Figure[PrintComposerAddScalebar]. To change the scalebar:
Select the scalebar from the map
Click on Item Properties from the left-hand panel
Under Segments
Set left 0 and right 2
Set Size to 1000
Set Height to 2 mm
Next, we'll add a legend:
From the main menu, select Layout > Add Legend
Click somewhere within the upper right-hand box
QGIS will automatically add a legend for all the layers loaded in thecanvas. We can edit the legend's settings and remove the legend entriesthat we do not want to show. Manual edits of the legend text can also beperformed to make it more readable.
To be able to edit the legend items, you first need to untick the box for Auto update. Use icons under the Legend items to edit or change the order of the items.
From the right-hand panel, click on the Item properties
Under Legend items:
Select London_boroughs and then click on the red
minus sign
Select MSOA_GL_ElecUsage and click on the edit
sign, a new window will appear.
Change the content of Item text to Electricity
Usage
Click on the first value 2576.2400 – 3000.0000
and select edit sign to change the range to
2000 – 3000
Repeat for the rest of the values to round them
and remove any unwanted zeros.
To add an overview:
Add a new map (Map 1) to the place-holder between
the map legend and the logos
For Map 1, from the Item properties,
Under Main properties
Select Lock layers for map item
From the visibility preset, select overview map
Under Overviews tab
Click on the plus sign,
Overview 1 should be added to the overview list
Ensure Draw "Overview 1" overview is selected
For Map frame, select Map 0
The map is now almost ready. You can export it as PNG or a PDF. Or you can keep reading foreven more excitement!
The map is now ready to be printed or outputted as an image. But, we aregoing to use this layout as a template and auto-generate energyconsumption for each borough.
To set the coverage (this is already set, but make sure the option isenabled):
While Map 0 (the main map) item is selected, click on
Item properties from the right-hand panel
Select the option for Controlled by atlas generation
You can change the Margin around feature if you like, but we cankeep at 10%. Further settings are also required:
Click on Atlas generation tab from the right-hand panel
Tick the box for Generate an atlas
Under Configuration, for Coverage layer select
London_boroughs
Under Output, for Output filename expression type:
'energy_'|| "NAME"
The expression for output will set the name of each output file. In thisexample we are going to have a name with 'energy_' combined withthe value of NAME column (what do you think this value is?)
To generate the maps:
In the print composer, from the main menu, select
Atlas > Export Atlas as Images...
Select a folder to output maps and press Choose
The process may take a while but you will eventually have 33 maps of theenergy consumption for each borough. Note the overview for the maps andalso the naming of the output files. SeeFigure beloq as an example of the maps created.
Let's make the QGIS work for you
Lutra Consulting is a QGIS-focused expert provider of geospatial software development, consulting, training, and support services.