Using GeoPandas to Visualize the 2015 Population Density of the Philippines
Population density is a crucial concept in urban planning. Theories on how it affects economic growth are divided. Some claim, as Rappaport does, that an economy is a form of “spatial equilibrium”: that net flows of residents and employment gradually move to be balanced with one another.
The thought that density has some sort of relationship with economic growth has long been established by multiple studies. But whether the same theory holds for the Philippines and to what predates what (density follows urban development or urban development follows density) is a classic data science problem.
Before we can test out any models, however, let’s do a fun exercise and visualize our dataset.
The 2015 Philippines’ Population Dataset
The Philippine Statistic Authority publishes population data every five (5) years. At the time of the writing, only the 2015 Dataset is published so we will be using this.
import pandas as pd import matplotlib.pyplot as plt import matplotlib.colors as colors #to customize our colormap for legend import numpy as np import seaborn as sns; sns.set(style="ticks", color_codes=True) import geopandas as gpd import descartes #important for integrating Shapely Geometry with the Matplotlib Library import mapclassify #You will need this to implement a Choropleth import geoplot #You will need this to implement a Choropleth %matplotlib inline
A lot of the packages we will be using needs to be installed. For those having trouble installing GeoPandas, check out my article about this. Note that geoplot requires cartopy package and can be installed as any dependencies discussed in my article.
Shapefiles are needed to create “shape” to your geographical or political boundaries.
Download the shapefile and load it using GeoPandas.
An important note here when extracting the zip package: all the contents should be in one folder, even though you will simply be using the “.shp” file or else it won’t work. (this means that the “.cpg”, “.dbf”, “.prj” and so forth should be in the same location as your “.shp” file.
You can download the shapefile of the Philippines in gadm.org (https://gadm.org/).
Note: You can likewise download the shapefiles from: PhilGIS (http://philgis.org/). It will probably be better for Philippine data though some of it is sourced with GADM, but let’s go with GADM as I have more experience in it.
#The level of adminsitrative boundaries are given by 0 to 3; the details and boundaries get more detailed as the level increase country = gpd.GeoDataFrame.from_file("Shapefiles/gadm36_PHL_shp/gadm36_PHL_0.shp") provinces = gpd.GeoDataFrame.from_file("Shapefiles/gadm36_PHL_shp/gadm36_PHL_1.shp") cities = gpd.GeoDataFrame.from_file("Shapefiles/gadm36_PHL_shp/gadm36_PHL_2.shp") barangay = gpd.GeoDataFrame.from_file("Shapefiles/gadm36_PHL_shp/gadm36_PHL_3.shp")
At this point, you can view the shapefiles and examine the boundaries. You can do this by plotting the shapefiles.
#the GeoDataFrame of pandas has built-in plot which we can use to view the shapefile fig, axes = plt.subplots(2,2, figsize=(10,10)); #Color here refers to the fill-color of the graph while #edgecolor refers to the line colors (you can use words, hex values but not rgb and rgba) country.plot(ax=axes, color='white', edgecolor = '#2e3131'); provinces.plot(ax=axes, color='white', edgecolor = '#2e3131'); cities.plot(ax=axes, color='white', edgecolor = '#2e3131'); barangay.plot(ax=axes, color='white', edgecolor = '#555555'); #Adm means administrative boundaries level - others refer to this as "political boundaries" adm_lvl = ["Country Level", "Provincial Level", "City Level", "Barangay Level"] i = 0 for ax in axes: for axx in ax: axx.set_title(adm_lvl[i]) i = i+1 axx.spines['top'].set_visible(False) axx.spines['right'].set_visible(False) axx.spines['bottom'].set_visible(False) axx.spines['left'].set_visible(False)
Darker fills imply more boundaries
Load Population Density Data
Population data and Density per SQ Kilometers are usually collected by the Philippine Statistics Authority (PSA).
You can do this with other demographics or macroeconomic data as the Philippines have been advancing on the provision of these. (Good Job Philippines!)
Because we want to amp up the challenge, let’s go with the most detailed one: the city and municipality level.
💲 Live CollabPlay: https://youtu.be/B6LCFSPdsE0 💲 Hospedagem com Desconto Exclusivo: https://tekers.tech/4e587 Não é todo programador que gosta de compartilh...
#vscode Hello, my friends and fellow developers, this video is all about User Snippets. That means the Snippets (Code Shortcuts) that you can make for yourse...
We are pleased to announce that the July release of the Python extension is now available for Visual Studio Code. You can download the Python extension from the Marketplace, or install it directly from the extension gallery in Visual Studio Code. If you already have the Python extension installed, you can also get the latest update by restarting Visual Studio Code. You can read more about Python support in Visual Studio Code in the documentation .
If you’re looking for a fast and lightweight open-source code editor, Visual Studio Code has you covered. Come for a deep dive into the features of Visual Studio Code which provide a rich, productive environment for C++ development.
We speak to the creator of Visual Studio Code about the early challenges to now becoming the most popular development environment in the world.