Thematic maps of local government areas
I have a cunning plan, to write a web application that automatically generates a Google map showing thematic data from an ESRI shape file. On a previous contract for Leicester County Council I used MapInfo’s MapXtreme for Java to render raster maps for each request, but found that it can often take up to 20 seconds to render a complicated thematic map.
So instead I want a web app that lets you choose from a list of Local Authorities in the UK, offers the chance to enter data for each Super Output Area and then automatically generates the coloured tiles needed to make a google map. (Later on I’ll provide a way to upload and validate data in a spreadsheet).
Richard Milton from the CASA project at UCL has produced a desktop application called Google Map Creator. This is a Java Swing application and provides a handy starting point for the new web app. I used a Java decompiler to peek inside the source code and found six classes that read the ESRI shape files and produce the tiles. Next I created a new Java package from these classes and stripped out all of the Swing stuff. Having tested the new classes in a standalone Java application, I added them to a new Java Struts application.
But I want to write all of this quickly, so will use Ruby on Rails instead of Java. I thought about finding out how to access Java from RoR but realised that I might as well keep Richard’s code in its own Java web app and call it using HTTP from the Ruby web app.
I host both J2EE and Ruby stuff on this server (as well as Drupal, Wordpress, Expression Engine and MoveableType).
Next I got hold of a CD (from the most efficient Civil Servant in the country) containing an ESRI shapefile for all Super Output Areas. The snag was that it really is one Shapefile for the whole UK, much too big for convenience. Although there is a free shapefile viewer from ESRI, you need to pay them for software to chop and change the files, except that the shapefile file format is public.
Now I think laziness is a virtue in a programmer’s character, and so I had a look around to see if anybody had produced any tools to edit Shapefiles for free. Somebody had! Shapelib is written in C, great, I’ve been doing C since before Internet time (1986). The only thing is its a fiddle, and as I mentioned I want to do this quickly in Ruby.
One of the nice things about Ruby and RoR is the sheer number of additions that people have already created, and one of those is Ruby Shape Lib, a wrapper for the C Shapelib library. In common with others on the sourceforge forum I could not get it to build on windows, so I ducked and dived and compiled it on Unix instead, after all thats where its going to be hosted.
Despite having written several web apps with RoR, I don’t know much Ruby. So I pulled the Pick axe book off the shelf and got down to writing some a Ruby script to chop up the nationwide shapefile using Ruby Shape Lib. It was easy and fun, and we all do our best work while having fun, I know that from watching our children.
Next time: building the finished RoR web app.