breathe in, breathe out
A cartogram is a map which has been distorted according to some numerical value, such as population (as shown above)
One of the problems with cartograms is that it's sometimes difficult to tell which region is which, as the shapes are distorted, change in size and position. By animating ('tweening') between the original and cartogram images, it's possible to understand how these factors influence the final result.
The cartogram was produced with ScapeToad; the original polygons came from NaturalEarth.
Cleaning the data
The resulting polygons from ScapeToad were mixed; a combination of simple POLYGONs, and MULTIPOLYGONs for some countries. To fix this, I used QGIS 'Multipart to Singlepart' to get them consistent.
The ScapeToad polygons were also smoothed, and had more vertices/nodes than the original.
Dividing the polygons
To get around this, I used the QChainage QGIS plugin. This allowed me to create a fixed number of equally spaced nodes around each country's border (200 in this case). This was repeated for the original map and the cartogram. These POINT layers were then exported to CSV with XY geometry.
Doing the animation
A custom python script then read the two CSV files, matched up the nodes one-by-one, and interpolated each point along the line between the geographic position and the cartogram position.
The result of each frame was appended to a single CSV file along with a unix timestamp, starting with 0,1,2... These correspond to 1st Jan 1970 - you can see this in the bottom right of the animation.
Finally, QGIS Time Manager plugin was used. This lets QGIS render each frame separately to its own png file. All points with timestamp 0 go in the first frame, timestamp 1 for the second frame and so on.
Once this was done, ffmpeg was used to create an mp4 video (I had to hide all the pngw world files to get this to work).
The gif animation in this post was created using the ImageMagick convert command.