Static Maps and Spatial Join with GeoPandas

Post navigation

The case study

My first major mapping project at the University of Chicago is a choropleth map of Sri Lankan Army (SLA) officer deaths between 1981 and 1999. The data is collected painstakingly by my colleague, Winston Berg. I am deeply grateful to Professor Paul Staniland, who made the project possible by hiring me. Any mistakes remain my own. You can see a copy of the codes here and the final products on my GitHub repository.

The data

The data table includes the names of army officers who died as well as their place of death, which may be a village or city. In order to assign each place of death a larger geographical category — province, district, or division — we must attach a longitude and a latitude to each place in the dataset. Thankfully, GeoPandas has just the function.

“out.csv” describes deaths data in which every place name is matched with a longitude and latitude.

Base Map Shapefile

Go to http://www.diva-gis.org/gdata and download the shapefile for Sri Lanka. Province level, district level, and administrative division levels are available. A later blog will explain how to make shapefiles based on existing ones.

Get mapping!

Now that we have both the data and the shapefile base map, we can start mapping! In this example, I use Sri Lankan districts.

Open a jupyter notebook in your working directory and import the following

Spatial join

To make a heat/choropleth map, we have to count how many deaths there are per district. For this, we use GeoPanda’s spatial join function. The spatial join function matches points in the deaths dataset to the polygons in the geo-dataframe. Here, I use “within”. You can also use “contains ” or “intersects”.

Produce the map. The default for “scheme” is quantiles. You can also use “equal_interval” or “fisher_jenks”. Fisher_jenks sets categories by minimizing in-group variance and maximizing inter-group variance.