Saturday, February 8, 2014

Finding murders with OpenStreetMap

Since the end of the nationwide suspension of capital punishments in 1976, 1365 people have been executed in the US. Only 13 convicts were female and a majority of 87 per cent died by lethal injection. Alarming 34 per cent were black, which is around 2.5 times the number that should have been doomed according to the distribution of population. The most executions were done in Texas (509).

The Death Penalty Information Center (DPIC) offers a detailed database including all executions and necessary details to map the cruelty. After an informal mail correspondence, I received the approval to use the database for non-commercial use as long as I mention the source. Their site is not clearly giving copyright information, thus I recommend to ask for permission before you publish something derived from their data.

DPIC’s database is not providing coordinates but county names, which is why it is a good source to show how you can geocode your data when you only have place names. Nominatim is a great extension using OpenStreetMap to do geocoding or reverese geocoding. The best thing about it is that Nominatim has an API interface and thus you can do the geocoding with a script. My programming skills are very rudimentary but I had experienced assistance to develop a well working Python script for a former project. Adapting a few lines in the script, it was easy to send my county names and state names to Nominatim and get back the lat and lon values for each county’s weighted centre. There are several scripts that you can use with Nominatim or Google Maps in case you also want to avoid a lot of handwork when geocoding. You will find them online.

Using Python to geocode (input: red, output: green)

After data cleaning and saving the worksheet to a .csv file, QGIS’ Add Delimited Text Layer tool can easily import the execution data and you can save it to a point Shapefile.

Adding lat lon data to QGIS
I wanted to present the data in a catchy way so I adopted some of Anita Graser's ideas. Her blog helps a lot when learning about QGIS functions and to get some inspiration for your projects.

To make the map as patriotic as possible, you can use the new blending functions in the Print Composer and add an American flag. Anita describes how to do that in her post on making vintage maps. Moreover, I chose to also use the newly introduced Data defined properties to present each jail in relation to the number of executed convicts. Anita explains that function in her project about meteorite landings.

Data defined properties styling

Finally, we need to create a legend. Since QGIS 2.0.1, you can use HTML tags to arrange your annotations. My HTML skills are as rudimentary as my programming skills, so I only added some basic text styling.  

I don’t know much about the death penalty in the US, so I was quite surprised that there is a huge difference between the West and the East Coast. I am interested in the factors that caused this heterogeneity. The main reason should be the unequal distribution of population but there could be also historic reasons related to the colonization of the States and still persistent differences in the attitude of people or it might be just a coincidence of law regulations. I guess it is a mixture of everything. Let’s just hope that there will be more blue hatched states and less red circles in the future.

Monday, February 3, 2014

Oh, hello Asiafrica!

How to use Wikipedia to create animated maps.

Geodata is everywhere but there is one major obstacle that prevents constructing beautiful maps with it. Many databases are containing all elements to provide geodata but lots of these databases are not intended to supply users with geographic information and attributes in a way that you can easily use them for mapping. There are thousands of ideas for possibly amazing maps that could be created if there was sufficient data or time to extract and prepare it. 

If you want to produce geodata by yourself, a look at Wikipedia can be very helpful. There are lists of earthquakes, most western points of countries and so on that contain lat and lon values already. You can easily import these using the Add Delimited Text Layer function in QGIS. Moreover there are lists that contain geographical information that you can symbolize by a country’s or city’s name. The utilization of these lists for GIS is sometimes a little bit tricky. For example, the list of terrorist attacks would need some geocoding whereas data that is linked to a whole country can be visualized using the Join function.

The recent project about where the bad guys vote made me interested in creating another cartogram. Inspired by the demographic animation of Germany I decided to also work on a project that shows a development within a certain period. 

The Wikipedia list of countries by past and the future population provides the population of nearly every country from 1950 to 2050 in a 5 years interval. Thus, it is possible to generate 21 cartograms to visualize the whole Wikipedia list in one animation.

To import the list we can take the link of the demanded Wikipedia site, open Excel and paste it into the File Name text box just like we would open any other file stored on our computer. The whole site will be opened and look a little bit clumsy but it is now easy to extract the list data in a new worksheet and we can prepare the data to join it with a global dataset that includes country names. I decided to take data from Natural Earth.

After saving the joined data to a new Shapefile, we can start creating cartograms with Scape Toad for every year. It will take some time!
By the creation of 21 cartograms, we have a good number for our animation. After styling and exporting each cartogram via QGIS’ Print Composer the cartograms can be compiled to an animated GIF by using an image manipulation programme like GIMP

Lots of Layers and a lot of handwork for styling and export

Creating an animated GIF with GIMP

It took me some time to figure out a decent styling. In fact, I do not like this colourful presentation of the continents but it turned out to me the most reasonable styling. First, I tried to use one graduated colour for all continents but it made the impression that there is some kind of order or importance within the continents. Thus, I ended up using the colourful symbolization.

As you can see, the animation illustrates the decrease of population in Europe compared to Asia and then at around 2015 also in relation to Africa. It seems to be only a matter of time until the Europeans actually need something that is more forceful than Frontex to “protect” against refugees crossing the Mediterranean Sea.