eyecatch

Weather Forecast Map: Moving Islands in QGIS

Published: Last updated:
This article uses QGIS 3.34. The current LTR is 3.44.

What you'll learn


  • How to display features at a location different from where they actually are

Recommended for


  • Anyone creating a thematic map who wants to move features to somewhere other than their real location

Introduction

While working in QGIS, have you ever wanted to move a distant feature into an empty spot on the map? Weather forecasts, for example, often show a map with the Ryukyu Islands drawn on the Sea of Japan side.

Example of a weather forecast map
Example of a weather forecast map

You can recreate this in QGIS by moving the features themselves, but their positions then no longer match the real locations, which makes it a poor approach. This article shows how to get the same result with the geometry generator instead.

This article is a revised version of the “QGIS Blog” content that was published on the MIERUNE Inc. website.

What is a geometry generator?

The geometry generator is a feature that uses an expression to control how a geometry is displayed. Because it draws the geometry as a symbol of an existing layer, you can change where a feature appears without changing its actual location.

Points displayed at the centroids of the administrative boundary layer using the geometry generator
Points displayed at the centroids of the administrative boundary layer using the geometry generator

How to use the geometry generator

This example uses administrative area data to create the kind of map often seen in weather forecasts.

First, download the nationwide Administrative Area Data (2019) from National Land Numerical Information.

Download the nationwide Administrative Area Data (2019) from National Land Numerical Information
Download the nationwide Administrative Area Data (2019) from National Land Numerical Information

Extract the data, then import N03-19_190101.shp into QGIS. The Japanese archipelago appears.

Next, change the project's coordinate reference system (CRS) to EPSG:3857.

Change the project CRS to EPSG:3857
Change the project CRS to EPSG:3857

In the Layers panel, right-click N03-19_190101 and select Properties. On the Symbology tab, select Simple Fill, open the Symbol layer type drop-down list, and select Geometry Generator.

Select Geometry Generator as the Symbol layer type
Select Geometry Generator as the Symbol layer type

An expression field appears below Units. Copy and paste the following expression into it.

case
	when "N03_001" = '沖縄県' then
	translate($geometry, 5, 15)
else
	$geometry
end
Enter the expression in the field
Enter the expression in the field

The map canvas now shows the Ryukyu Islands moved to the upper left of Honshu.

The Ryukyu Islands moved to the upper left of Honshu
The Ryukyu Islands moved to the upper left of Honshu

In brief, the expression uses a case statement to pick the features whose N03_001 field is 沖縄県 (Okinawa Prefecture), and the translate function shifts them.

translate(geometry,dx,dy)

geometry: the geometry
dx: shift in the x direction
dy: shift in the y direction

While you're at it, add a line too, using Layer → Create Layer → New Temporary Scratch Layer.

Add a line to separate the Ryukyu Islands
Add a line to separate the Ryukyu Islands

The map now looks just like one from a weather forecast, and it was easy to make. You can also change the size of features by combining the scale function.

This time, enter the following expression on a layer where the data above has been dissolved by prefecture. Be careful: if you use the scale function without dissolving, features overlap each other.

case
	when "N03_001" = '北海道' then
	scale(translate($geometry, -8,-2),2,2)
else
	$geometry
end

Hokkaido really is big next to Honshu!

Hokkaido displayed at twice its size with the scale function
Hokkaido displayed at twice its size with the scale function

* Hokkaido is shown at twice its size, so it differs from its actual size.

Conclusion

The feature covered in this article is based on this X (formerly Twitter) post. It should also be useful when preparing deliverable drawings, so give it a try!

About the author
QGIS LAB Editorial Team
QGIS LAB Editorial Team

QGIS LAB is a comprehensive information hub for QGIS, the open-source GIS software. Under the concept of “Geospatial for Greater Good,” we share the knowledge and skills to open up the world through location data.