The case study
In last week’s post, we used open source shapefiles and folium base maps to create choropleth maps. But this is not always possible. In my work, I found open source shapefiles for Sri Lanka’s provinces, districts, and administrative divisions, but not the country’s polling divisions. Luckily for us, the 323 administrative divisions of Sri Lanka can be merged into around 160 polling divisions, using the map below as the basis. The final shapefiles and intermediate geojson file can be found in my GitHub repository.
The first step is to download a .kml file of Sri Lanka’s 323 administrative divisions, which we will use to merge and create the shapefile of the country’s polling divisions. Go to http://www.gadm.org/country, and choose the Google Earth .kmz option. On the following screen, download the level 2 data. Use an online converter to convert the .kmz file to a .kml file.
Next, go to geojson.io. Click “Open” on the left top corner, and select your file. After opening your file, geojson.io will plot the shapefile for you. Go to the right side of the screen, and click on “Table.”
Navigate back to the map and click on any shape on the map. A mini table will pop up, as the image below shows. Click on “Add row”. In the new row, type “polling_division” for the header, and the number corresponding to that polling division in the image above. This creates a new column in the right-hand-side table, called “polling_division”. Fill in this column for all 323 administrative divisions.
Worth mentioning is that this process is made easier if you load a .kml file for the districts on top or below the administrative division file. This makes it easier to distinguish the divisions and not get mixed up, since you’ll be doing one block of land at a time.
After you are done with filling in the “polling_division” column, double check to make sure that all admin divisions with the same polling division number are contiguous. Polling division 96, for instance, shouldn’t appear both in Batticaloa and Colombo.
After double checking for contiguity, click “Save” on the top left and save the file as a GeoJSon file (also in my GitHub repository).
Go to mapshaper.org and select the GeoJSon file you just saved. Go to the top right corner and click “Console”. Click on the “i” below the top bar — when you hover over each region, you can see the information pertaining to that administrative division.
In the console on your left, type “dissolve polling_division”. The contiguous admin divisions you specified earlier as belonging to the same polling division will be merged into a single feature. In the map below, the tiny blue lines are the original admin divisions, and the black lines demarcate the polling divisions.
From this shapefile, we can see patterns of SLA deaths and electoral turnout, which is available by polling divisions. We can see that, unsurprisingly, regions with greater violence saw lower electoral turnout.