opensource.google.com

Menu

Introducing libkml: a library for reading, writing, and manipulating KML

Thursday, March 27, 2008

By Michael Weiss-Malik, KML Product Manager

KML has seen tremendous uptake as a GIS data presentation language, in large part due to its simplicity. The ability to quickly and easily read or write small bits of KML by hand helps newcomers to rapidly experiment with the language and learn it. That said, the most interesting and sophisticated KML documents generally aren't created by hand... instead, authors tend to write computer programs to generate data-driven KML en masse. Programmers are often forced to roll custom KML-generating code for each such project. Likewise, mapping application developers have traditionally been tasked with writing one-off KML parsers if they want to read in and visualize KML data.

Both KML authors and consumers should therefore be pleased hear about today's version 0.1 "preview" release of libkml: Google's open-source reference library for reading, writing, and manipulating KML. Our hope is that libkml will reduce the need for everyone to re-invent the wheel with a custom parser or serializer, by providing a single re-usable library that implements KML's semantics. This first release is focused primarily on the low-level details of the KML DOM itself, but it's our intent to enhance the library in the future by implementing more sophisticated operations like style resolution and balloon text templating. If you don't know what these are, I encourage you to check out Google Code's KML documentation.

Our initial release covers parsing and serializing of all elements in KML 2.2, which is currently pending acceptance by the Open Geospatial Consortium as an OGC standard. It's a C++ library that compiles and runs on multiple platforms, so C++ is the most direct way to call into it. If C++ isn't your thing, the library's build system can also generate (through SWIG) wrappers/bindings for Java, PHP, Perl, Python, and Ruby. Since the whole thing is released under a BSD license, you have complete flexibility in how you use our code and/or integrate it into other projects. Do note that we're labeling this a "preview" release on purpose: you should expect changes.

I encourage you to download and play with the library -- it includes several example programs that are worth the price of admission in and of themselves. And keep an eye out in the coming months, because this first release is just the beginning!
.