Experimentations with libkml

As my first geographic database went, so did the scripts that I wrote to fish out the data.

When I started playing with GIS, I initially used a simple MySQL database without support for geographic extension. In fact, I went on to store my points as flat text — needless to say that the data (at least the geographic part of it) was not very useful after the project was finished.

Similarly, the scripts that I used to mash both the geographic data (electoral districts of Canada) and functional data (electoral results) in order to generate KML files were simply written in custom PHP, using the functions for manipulating XML (because KML is a XML-based language).

This was before I discovered libkml.

libkml is library for creating and parsing KML contents. It was first introduced in March 2008 by Google, as a open-source library for reading, writing and manipulating KML. It is written in C++, but thanks to SWIG, you can use libkml in Java and Python.

Map of all media bodies (tv, periodicals, newspapers) in China

I use libkml in Python, but so far only for generating KML. What you see here above is an example of how a KML that I created renders in Google Earth. It shows points of interest representing media outlets in China, in a yet to be released visualization project with my China Media Project colleagues. The idea is this: you have a geographic database with points of interest along with linked data. Then, in python, you fetch from the database and use libkml to output a KML file.

The main advantage that libkml provides is that it simplifies my code greatly, as I don’t need to reinvent the wheel, and that libkml is tailor-made for generating KML.

The trouble now is not so much the actual rendering or visualization part anymore. The challenge, I find, is more to finding quality data, especially of the geographical kind. But that’s going to be for another entry.

Leave a Reply