Strangely Correlated

Random stuff related to the web

Progress report: Google Maps and Dutch elections

I managed to make quite a bit of progress on this little experiment, and learn a bunch of stuff on the way.

Last time I ended with a kml-file that was viewable in Google Maps. All nice and well but not really useful, yet. Next step was to take the kml-file, extract the coordinates and use the Google Maps API to show them on a Google Maps. This all went reasonably well, there is built-in support for polygons and the API is easy to work with. The javascript right now is still rather slow and needs optimizing. Also, I might change bits of the AJAX-request to use jQuery instead of the API for readability and maintainability.

The speed of the loading might further be improved by using encoded polylines. Google has a format which renders the polygons faster than the kml-file and there is an algorithm for the conversion.  I’ll definitely look into this for speed-ups.

After this was done I had to convert the election results (a .csv) file to json to work with it in javascript. This was not too difficult using python. Since the elections for parliament in 2006 (the set I use for testing) some municipalities have merged or joined others. My kml-file therefore had different municipalities than the json file.  Looking for differences between the data sets I was able to find the incomplete municipalities. Wikipedia revealed the details of the mergers etc.  and I was able to merge them in the csv using Python.  The percentages still need to be calculated again but that’s no biggy (and can also be done in javascipt).

Last step was to assign colors to the polygons based on the values of the json file. I have this working although there is no clear algorithm yet. Through a stroke of luck my feedreader turned up this item today giving me all the information I needed for the coloring, especially through this application. When I have time I’ll use it to further patch things up.

Steps remaining is using the encoded polylines, use jQuery (which should also fix a bug in Firefox of rendering the polygons a bit strange) and give more election results as input.  I also stumbled upon Raphael, it looks excellent and might use it for some extra graphs.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: