Aggregating WorldPop Counts to Folium Choropleth

For this blog, I will aggregate the WorldPop population TIF files to customized hexagon shapes to reduce storage space and improve readability. The workflow will consist of three steps:

  1. Get WorldPop TIF file
  2. Create custom hexagon shapes and aggregate
  3. Plot with folium choropleth

The WorldPop is an organization, started in 2013, whose objective was to provide an open-access archive of spatial demographic datasets. They also offer an estimated population count dataset in a TIF format. The population counts were estimated using Random Forest methods to disaggregate census data to a resolution of 100x100m. Please check them out here:

The second objective is to create custom hexagon grids that will fit into Paraguay, South America. I first used a country-level shapefile and overlayed a hexagon grid using QGIS: MMQGIS. I then select the hexagons that contain the shapefile and extract it as a ‘gpkg’ file. This file will be our shapes to aggregate the estimated population count.

I downloaded the country-level shapefiles from More specifically, the zip files that contain the administrative level 0–4 boundary shapefiles. <download link>

Extract the boundary shapes into somewhere accessible and download QGIS. QGIS is an open-source desktop platform to visualize and edit geospatial data.

Download QGIS and install from here:

After installation, load the admin level 0 (country level) of Paraguay in QGIS by navigating your directory through the ‘Browser’ card on the left side of the application. The view should display something like below (minus the random color assignment).

I now need to install the MMQGIS plugin through the QGIS menu tab. After installation, I can create hexagon grid layers on top of the first layer. Please look at the following steps to install MMQGIS and create grid layers:

Step 1:
Navigate through the Menu Tabs and choose Plugins → Manage and Install Plugins…

Step 2:
Search for ‘mmqgis’ and install plugin.

Step 3:
Navigate through the menu tabs and select
MMQGIS → Create → Create Grid Layer

Step 4:
I change the Geometry Type to ‘Hexagons’ and Extent Type to ‘Layer Extent.’ I will want to create hexagon grids on top of the first countrywide layer. I can adjust the X spacing to change the hexagon’s size, and I will set it at 0.1. Change the output file name and directory to somewhere you are comfortable accessing and click apply.

Step 5:
The hexagon grid layers should overlap the first country-level shapefile. I will need to select the hexagons that intersect with the first layer. On the top of the application, look through the Vector tab → Research Tools and choose ‘Select by Location…’.

Step 6:
Select the ‘intersect’ feature and compare the grid layer with the original countrywide shapefile. After changing the ‘By comparing to the features from’ section, click run.

Step 7:
The output should have highlighted the hexagons that intersect with the original shapefile. Save the selected feature on the layers card as shown below:

Step 8:
Save the selected layer as a geopackage file to a folder.

For this blog, I saved the gpkg file to the directory ‘/data/shapefile.’ The output of the intersected hexagon layers should look like this:

I now have the polygon shapes and will now populate it with the sum of the points that belong to it.

I have now aggregated the population counts (originally 100m x 100m) into hexagon shapes created with QGIS. All that’s left is to plot it with folium using folium.Choropleth.

Thank you for making it all the way to the end of the blog! I hope this walkthrough was helpful to your project and would appreciate any feedback.

Hello! My name is Albert Um.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store