This article describes how to join country geometry from GISCO with attribute data from EUROSTAT and save it as GeoJSON. This type of GeoJSON is great for creating choropleth maps. We will also cover how to upload GeoJSON to MapTiler Cloud.
In this tutorial, we cover just data preparation for web choropleth map. If you want to create such a map we recommend you to read also tutorials that shows how to add GoJSON to a map with Maplibre, leaflet, or OpenLayers library.
Prepare the data
We will work with data from EUROSTAT. First, we will need the geometry of European countries. (The geometry layer doesn't have to be in GeoJSON format. The GeoJSON format will be created by export of geometry joined with attribute data. However, in the following lines we work with GeoJSON geometry).
PRO TIP: Whole Europe is visible approximately on zoom 3, which corresponds to 1:73,957,338.86 map scale in 96 dpi. You can read more about map scales and zoom levels here. The best scale for our choropleth map is 1:1 000 000. Of course, it is possible to change geometry generalization as you go through zoom levels.
Then we need categorical or quantitative data, which will be displayed in the choropleth map. Remember that you should have relative values such as population density for the choropleth map, not the number of people. We will use categorical data of the mean age of women at first marriage in 2019, which can be filtered from the Marriage indicators dataset. (Filters - Time: 2019, Geopolitical entity: countries, Demographic indicator: mean age at first marriage - females)
PRO TIP: In the format tab, select codes instead of labels. These codes are better suited for connection with a geographical representation.
After download, it's necessary to remove the header and footer of the spreadsheet and rename the headers of each column ideally to one word without spatial characters. The final document should have just one sheet with two columns named GEO_code and Age.
Join of spatial and attribute data
Open QGIS. Open edited table with a mean age of women at first marriage as a layer and select CNTR_RG_10M_2020_4326.geojson from GeoJSON countries. Right-click on CNTR_RG_10M_2020_4326.geojson layer and select properties → joins → green plus sign
Well done! You just joined spatial data with attributes. However, this is just a temporary connection, which will become permanent after export. CNTR_RG_10M_2020_4326.geojson layer contents countries of the whole world, but we want to have final GeoJSON only with countries that have values.
Right-click on CNTR_RG_10M_2020_4326.geojson → open attribute table → select feature using an expression: "Age" is NOT Null and "Age" is NOT ':' This expression will select just countries with some value.
Now it's good to check if our Age column is a number. If it's a number, the numbers will be alight to the right. If age is not a number, create a new field (decimal number (real) size 3 precision 1) and save values to it with the expression “Age”.
Now we can export: right-click on CNTR_RG_10M_2020_4326.geojson layer → export → Save Selected Features As and name it. In this phase, it is also possible to remove unnecessary attributes such as FID, CNTR_ID Age, or ISO3_CODE.
Upload GeoJSON to MapTiler Cloud
Go to MapTiler Cloud - maps in the Left Menu, select Data, and then select NEW DATASET.
Choose upload file under Upload dataset. Click on upload. Name and describe your dataset and click on Create. And that is all, you have successfully joined spatial data with attributes in QGIS.
Zoomable choropleth map from GeoJSON with MapLibre
Zoomable choropleth map from GeoJSON in Leaflet
Countries' geometries from EUROSTAT
Marriage indicators dataset
Please sign in to leave a comment.