Massachusetts Institute of Technology
Resources for Making Shapefiles by Merging
July 26, 2017
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 shown in Figure 1 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 (see Figure 2). On the following screen, download the level 2 data. Use an online converter to convert the .kmz file to a .kml file.
Figure 2. Database of Global Administrative Areas interface
Figure 1. Sri Lankan Parliamentary Polling Divisions
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 Figure 3 shows. Click on "Add row". In the new row, type "polling_division" for the header, and the number corresponding to that polling division in Figure 1. 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).
Figure 3. geojson.io
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 Figure 4 below, the tiny blue lines are the original admin divisions, and the black lines demarcate the polling divisions.
Figure 4. mapshaper.org
From this shapefile, we can see patterns of SLA deaths and electoral turnout, which is available by polling divisions. We can see from Figure 5 that, unsurprisingly, regions with greater violence saw lower electoral turnout.
Figure 5. Electoral turnout and SLA deaths by electoral districts