From OpenStreetMap Wiki
Jump to: navigation, search

Osmium is a C++ library, but it can also be compiled with Javascript support. It uses the very fast Google V8 Javascript engine also used in the Google Chrome browser. Much of the functionality of Osmium can then be used from Javascript. This combination of the fast C++ core with the Javascript JIT compiler gives you an enormous amount of flexibility without compromising on speed.

Osmium comes with the osmjs program. It gives you the Osmium and Javascript functionality in a nice package. Its major use is as a flexible exporting engine. Exporting OSM data is always problematic, because of the complexity of the open tagging scheme. There are many many different ways OSM data can be exported and the right approach depends on what you want to do with the data.

Most OSM conversion and exporting tools give you some kind of config file that allows you to map OSM tags to output attributes. But this is often not enough. Think of two examples:

  • Roads can have oneway tags. Allowed and often used values include "1", "yes", "true", "false", and "-1". In the output (say a Shapefile or PostgreSQL table you just want boolean (yes or no). You have to map "1", "yes", "true", "-1" to yes and "false" to no. In addition you have to turn the order of the nodes in the way around if it is "-1".
  • If you want to generate maps for specific languages, you have to look at several different tags to decide which name you want to use for labelling: "name", "name:LANGUAGE", "local_name", etc. Depending on what you want to do exactly, you might prefer one of the other name, etc.

Many other cases are difficult or impossible to do properly in most conversion or exporting tools. But because Osmium uses Javascript to define this mapping, it's easy with Osmium.

For the usual simple cases it seems a bit much to have to write Javascript instead of just using a simple config file. For these cases Osmium comes with a export library written in Javascript that has a very simple interface that almost looks like a config file. Simple, standard mappings can be written easily, but you can always include Javascript functions to do more complex things. The library follows Alan Kay's motto: "Simple things should be simple, complex things should be possible."

See also