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:
- Get WorldPop TIF file
- Create custom hexagon shapes and aggregate
- Plot with folium choropleth
Get WorldPop TIF file
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: https://www.worldpop.org/
Create custom hexagon shapes and aggregate
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 https://data.humdata.org/dataset/paraguay-administrative-level-0-boundaries. 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: https://www.qgis.org/en/site/forusers/download.html
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:
Navigate through the Menu Tabs and choose Plugins → Manage and Install Plugins…
Search for ‘mmqgis’ and install plugin.
Navigate through the menu tabs and select
MMQGIS → Create → Create Grid Layer
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.
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…’.
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.
The output should have highlighted the hexagons that intersect with the original shapefile. Save the selected feature on the layers card as shown below:
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.
Plot with folium choropleth
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.