3

I was wondering if anyone knows of any FOSS tools to animate cartograms?

By this, I mean 'tweening' between the geographic shapefile and the cartogram version of a shapefile.

This means gradually changing / morphing / interpolating one polygon into another. The "before" and "after" polygons have identical numbers of nodes, but each of these nodes will have different positions.

There's an example here on the ESRI blog.

They don't do the animation uniformly, they pass across the polygons in increasing longitude order, but it gives an idea of the effect I'm after.

I've been using ScapeToad to do cartograms, and it looks as if it generates a cartogram shapefile with the same number and order of vertices as the original shapefile.

This means I should be able to write code that interpolates each node along a line from its geographic position to its distorted position - perhaps with 'easing' (so the position on the line isn't linear interpolation, more like points on a sine-wave)

Is there already a library or plugin which can interpolate polygons in this way?

  • 1
    have you seen this QGIS plugin, gis.stackexchange.com/questions/72328/…. You could take a look at the python source code. – artwork21 Jul 28 '15 at 0:05
  • thanks for that, I hadn't seen that plugin. It looks as if it needs a bit of work on it to get it working on the newer versions of QGIS, though. – Steven Kay Jul 28 '15 at 12:48
  • There are cartograms made with d3 and TopoJSON that achieve a similar effect to what you want, check e.g. http://prag.ma/code/d3-cartogram – chkaiser Sep 7 '15 at 19:22
2

yes! I worked it out.

ScapeToad outputs mixed geometries - MULTIPOLYGON and POLYGON. I fixed this using "Multiparts to Single Parts". It also interpolates, so that there are more points in the output polygons (this depends on the quality setting).

To get around this, I used the QChainage plugin to create 200 equally spaced points on both the original and cartogram polygons (I had to convert these layers to lines first). This doesn't guarantee 200 points per polygon - either 200 or 201.

Next, export the two chainage POINT layers as CSV, with XY geometry.

Finally, a quick Python script to interpolate each point so that it's 50% of the way to the same point in the cartogram!

White is the original shapefile, red is the cartogram shapefile, and yellow is the 50% interpolation between the two.

enter image description here

With a bit of work, I should be able to use the Time Manager plugin by @underdark to do an animation...

  • how about the "quick" Python script, so ppl could really benefit from your findings? ; – Bernd V. Jul 28 '15 at 21:44
  • 1
    @Bernd V. I'll put it on Github once I've got it to work with Time Manager ;) – Steven Kay Jul 29 '15 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.