Often one needs to create a map that can be printed or published. QGIS has a powerful tool called Print Layout that allows you to take your GIS layers and package them to create maps.
The tutorial shows how to create a map of Japan with standard map elements like map inset, grids, north arrow, scale bar and labels.
We will use the Natural Earth dataset - specifically the Natural Earth Quick Start Kit that comes with beautifully styled global layers that can be loaded directly to QGIS.
Download the Natural Earth Quickstart Kit.
Data Source [NATURALEARTH]
Natural Earth quick start
folder in the Browser panel. Expand the folder to locate the Natural_Earth_quick_start_for_QGIS_v3
project. This is the project file that contains styled layers in QGIS Document format. Double-click the project to open it.Note
Project variables are a great way to store project-specific values for use anywhere you can use an expression in QGIS. The Natural_Earth_quick_start_for_QGIS_v3
project comes with many preset variables that are used for styling within that project.
project_language
variable and click on the Value column to edit it. Change the language to name_en
and click OK.z5 - 1:18m
folder and uncheck the box next to ne_10m_geography_marine_polys
and ne_10m_admin_0_disputed_areas
layers. Before we make a map suitable for printing, we need to choose
an appropriate projection. The default CRS for the project is set to EPSG:3857 Pseudo-Mercator
.
This is a CRS popularly used for web mapping and is a decent choice for
our purpose, so we can leave it to its defalt value. Go to .Note
For Japan, Japan Plane Rectangular CS is a projected coordinate reference system (CRS) that is designed for minimum distortions. It is divided in 18 zones and if you are working for a smaller region in Japan, using this CRS will be better.
Note
Leaving the layout name empty will assign a default name such as
Layout 1
.
10000000
as the Scale value.z5 - 1:18m
and activate the z7 - 1: 4m
group. This layer group has styling that is more appropriate for a zoomed-in view. Use the pan and zoom controls in the Map Navigation Toolbar and to zoom around Tokyo.Map 2
object that we just added from the Items panel. Select the Item properties tab. Scroll down to the Frame
panel and check the box next to it. You can change the color and
thickness of the frame border so it is easy to distinguish against the
map background.Map 1
object from the Items panel. In the Item properties tab, scroll down to the Overviews section. Click the Add a new overview button.Map 2
as the Map Frame. This tells the Print Layout to highlight the current object Map 1
with the extent of the map shown in the Map 2
object.Map 1
object from the Items panel. In the Item properties tab, scroll down to the Grids section. Click the Add a new grid button, followed by Modify grid....4326
in the Filter box. From the results, select the WGS84 EPSG:4326
as the CRS. Click OK.5
degrees in both X and Y direction. You can adjust the Offset to change where the grid lines appear.Degrees
but it appears as a number. We can customize is to append a ° symbol. Choose Custom
and click the Expression button next to it.concat(to_string(@grid_number), '° ')![]()
Map 1
for which to display the scalebar. Choose the Style that fit your requirement. In the Segments panel, change the Fixed width to 200
units and adjust the segments to your liking.GIS data has two parts - features and attributes. Attributes are structured data about each feature. This tutorial shows how to view the attributes of a GIS vector layer and do basic queries on them in QGIS.
The dataset for this tutorial contains information about populated places of the world. The task is to query and find all the capital cities in the world that have a population greater than 1 million and save the resulting subset as a GeoJSON file.
Natural Earth provides a Populated Places dataset. Download the simple (less columns) dataset
For convenience, you may directly download a copy of datasets from the link below:
ne_10m_populated_places_simple.zip
Data Source [NATURALEARTH]
ne_10m_populated_places_simple.zip
file in the QGIS Browser and expand it. Select the ne_10m_populated_places_simple.shp
file and drag it to the canvas.ne_10m_populated_places_simple
will now be loaded in QGIS and you will see many points representing
the populated places of the world. The default view in the QGIS canvas
shows the geometry of the GIS layer. Each point also has associated
attributes. Let’s view them. Locate the Attributes Toolbar. This toolbar contains many useful tools to inspect, view, select, and modify attributes of a layer.Note
If you do not see the toolbar, you can enable it from
ne_10m_populated_places_simple
layer and select Open Attribute Table.pop_max
label. You will notice that it is added to the expression section at
the bottom. If you aren’t sure about the field values, you can click the
All Unique button to see what the
attribute values are present in the dataset. For this exercise, we are
looking to find all features that have a population greater than 1
million. So complete the expression as below and click Select Features and then Close."pop_max" > 1000000![]()
Note
In the QGIS Expression engine, text with double-quotes refers to a field and text with single-quotes refer to a string value.
pop_max
attribute value greater than 1000000
.1
indicates that the place is a capital. We can add this criteria to our previous expression using the and operator. Enter the expression as below and click Select features and then Close."pop_max" > 1000000 and "adm0cap" = 1![]()
ne_10m_populated_places_simple
layer and go to GeoJSON
. GeoJSON is a text-based format that is used widely in web mapping. Click the ... button next to File name and enter populated_capitals.geojson
as the output file.name
and pop_max
columns. Click OK.populated_capitals
will be loaded in QGIS. You can un-check the ne_10m_populated_places_simple
layer to hide it and view the points from the newly exported layer.To create a map, one has to style the GIS data and present it in a form that is visually informative. There are a large number of options available in QGIS to apply different types of symbology to the underlying data. In this tutorial, we will take a text file and apply different data visualization techniques to highlight spatial patterns in the data.
We will take a CSV file containing the location of all power plants in the world and create a visualization showing distribution of renewable and non-renewable fuels used in these power plants.
World Resources Institute has compiled a comprehensive, open source database of power plants around the world covering over 30000 plants. Download the The Global Power Plant Database from the WRI Open Data Portal.
Natural Earth has several global vector layers. Download the 10m Physical Vectors - Land containing Land polygons.
For convenience, you may directly download a copy of the above layers from below:
globalpowerplantdatabasev120.zip
Data Source [WRI] [NATURALEARTH]
ne_10m_land
folder and select the ne_10m_land.shp
layer. Drag the layer to the canvas.ne_10m_land
added to the Layers panel. The global power plant database comes as a CSV file, so we will need to import it. Click the Open Data Source Manager button on the Data Source Toolbar. You can also use Ctrl + L
keyboard shortcut.globalpowerplantdatabasev120.zip
file. Select the global_power_plant_database.csv
. QGIS will auto detect the delimiter and geometry fields. Leave the Geometry CRS to the default value of EPSG:4326 - WGS84
. Click Add followed by Close.global_power_plant_database
will be added to the Layers
panel and you will see the points representing the power plants in the
canvas. Now we are ready to style both these layers. Click the Open the Layer Styling panel button at the top of the Layers panel.ne_10m_land
layer first. This will be our base layer so we can keep the styling minimalistic so it is not distracting. Click Simple fill
and scroll down. Select a Fill color as per your liking. Click the drop-down next to Stroke color and select Transparent Stroke
.
This will set the outlines of the land polygons to be transparent. You
will see the result of your selection applied immediately to the layer.global_power_plant_database
layer. Click on Simple marker
and scroll down. Pick a triangle marker.darker(@symbol_color, 130)![]()
Note
Note that this expression is independent of the fill color you have chosen. You will see that this is immensely useful in the following steps where it automatically sets the border color based on the fill color provided.
Categorized
renderer.global_power_plant_database
layer contains an attribute indicating the primary fuel used in each
power plant. We can create a style where each unique fuel type is shown
in a different color. Select primary_fuel
as the Column. Click Classify. You will multiple categories appear and the map rendering change accordingly.Rule-based
renderer. Select all but one rules by holding the Ctrl
key and clicking on each row. Once selected, click the Remove selected rules button to delete them.Renewable fuel
as the Label. Click the Expression button next to Filter."primary_fuel" IN ('Biomass', 'Geothermal', 'Hydro', 'Solar', 'Wind', 'Storage', 'Wave and Tidal')![]()
Note
The types of fuel chosen for renewable vs. non-renewable categories is based on Wikipedia. There are alternate definitions and classifications that may not match what is chosen here.
Non-renewable fuel
as the Label. Click the Expression button next to Filter."primary_fuel" IN ('Coal', 'Gas', 'Nuclear', 'Oil', 'Petcoke')![]()
Other
as the Label. Choose Else - Catch all for other features instead of a Filter. This will ensure that any category missed in the previous 2 rules, will be styled by this rule. Scroll down and click Simple marker. Choose an appropriate Fill color. Once done, click the Back button.Renewable fuel
rule and select Change Size.log10
function. You can experiment with different expressions to arrive at
what works best for your preferred visualization. Enter the following
expression and click OK.log10("capacity_mw") + 1![]()
Spatial Join is a classic GIS problem - transferring attributes from
one layer to another based on their spatial relationship. In QGIS, this
functionality is available through the Join attributes by location
Processing algorithm.
We will use 2 layers - A shapefile of Borough boundaries of New York city and another shapefile of Street Pavement Rating for all streets in New York city. The first task will be to find the average rating of streets in each of the borough using a spatial join with summary algorithm. The second task will be to add the name of the borough to the street features through a one-to-many spatial join.
NYC Open Data Portal is an excellent source of free data for New York city.
Download the Borough Boundaries zip file using the Export option on the portal.
Download the Street Pavement Rating zip file using the Export option on the portal.
For convenience, you may directly download a copy of the datasets from the links below:
Data Source [CITYOFNY]
nybb_19a.zip
file in the QGIS Browser and expand it. Select the nybb_19a/nybb.shp
layer and drag it to the canvas. This is a polygon layer representing the borough boundaries in New York city.V_SSS_SEGMENTRATING_1.zip
file and expand it. Select the dot_V_SSS_SEGMENTRATING_1_20190129.shp
layer and add it to the canvas. This is a line layer of all streets in the city.dot_V_SSS_SEGMENTRATING_1_20190129
layer. Right-click and select Open Attribute Table.Rating_B
which has values in the range 0-10 representing the street segment’s rating. The attribute RatingWord
has descriptive rating. We can use the Rating_B
field to calculate the average rating.NR
.
These are the segments that were not rated. Including them in our
analysis will not be correct. Before we do the spatial join, let’s set
up a Filter to exclude these records. Right-click the dot_V_SSS_SEGMENTRATING_1_20190129
layer and select Filter.NR
. You can also build the expression interactively by clicking on Field, Operator and selecting the appropriate Value. Click OK."RatingWord" != 'NR'![]()
dot_V_SSS_SEGMENTRATING_1_20190129
layer now has a filter icon indicating that there is an active filter
applied to this layer. Now we can do a spatial join using this layer. Go
to .nybb
as the Input layer. The street layer dot_V_SSS_SEGMENTRATING_1_20190129
will be the Join layer. You can leave the Geometry predicate to the default Intersects
. Click the ... button next to Fields to sumarize.Note
A tip to help you select the correct input and join layers: The input layer is the one that will be modified will new attributes in the spatial join. As we want the average rating field to be added to the borough layer, it will be the input layer.
Rating_B
and click OK.mean
as the summary operator and click OK. Now we are ready to start the processing. Click Run.Joined layer
layer added to canvas. Open the attribute table for this layer. You will see a new column Rating_B_mean
is added to the input borough layer with the average rating of all streets that are interesecting with that feature.Join attribute by location
algorithm for such analysis. The task is to add the name of the borough
to each feature in the streets layer based on which borough polygon it
intersects with. Before we run this algorithm, let’s remove the filter
from the dot_V_SSS_SEGMENTRATING_1_20190129
layer. Click the filter icon and press the Clear in the Query Builder. Click OK.Joined layer
in the Layers panel. Find the algorithm in the Processing Toolbox and double-click it to launch.dot_V_SSS_SEGMENTRATING_1_20190129
as the Input layer and nybb
as the Join layer. You can leave the Geometry predicate to the default Intersects
. Click the ... button next to Fields to add and select BoroName
. Click OK.Crate separate feature for each located feature (one-to-many)
. Click Run.Joined layer
. You will see that there is a new BoroName
attribute added to each street feature.The traffic department in the municipality of Norrköping is continuously monitoring accidents in order to make necessary improvements in the traffic environment. Your task is to make a couple of simple aggregations of collected data from 1999 and show the result on a map.
Open the map from this zip-archive in QGIS. You will see a map of Norrköping and a layer with traffic accidents.
The first task is do make a selection of all accidents with type = car (bil) and export it to a new layer. Remove the original layer. The next task is to calculate the number of car accidents in each city district.
Tip
Use join attributes based on spatial location (summary) to generate a new column in the table containing the needed numbers. To reduce the number of added columns you may choose to select only one field to summarise and select only "count" summary to calculate.
Show each car accident and the number of accidents per district with different colors and/or numbers in a map window on a map layout. The map should show the central parts of Norrköping and the scale must be 1:20 000. Other information on the layout shall be a legend, a north arrow, scale text, scale bar and your name. The stream through Norrköping must be shown on the map for orientation. Select the water from the land use layer (try different values of attribute "TYP" until you find the needed one) and export it to a new layer which can be placed above the city districts (use appropriate blue color for this layer).
Tip
Please refer to https://docs.qgis.org/3.4/en/docs/training_manual/map_composer/map_composer.html for an instruction on how to create and modify legend.