readosm  1.1.0a

Introduction

ReadOSM is a C open source library to extract valid data from within an Open Street Map input file. Such OSM files come in two different formats:

  • files identified by the .osm suffix simply are plain XML files.
  • files identified by the .pbf suffix contain the same data, but adopting the Google's Protocol Buffer serialization format (a more concise and compressed binary notation, thus requiring much less storage space).

The ReadOSM design goals are:

  • to be simple and lightweight
  • to be stable, robust and efficient
  • to be easily and universally portable.
  • making the whole parsing process of both .osm or .pbf files completely transparent from the application own perspective.

ReadOSM is structurally simple and quite light-weight (typically about 20K of object code, stripped). ReadOSM has only two key dependencies:

  • zlib (the well known ZIP library), which is used to decompress zipped binary blocks internally stored within .pbf files.
  • expat (a widely used XML parsing library), which is used to parse XML .osm files.
  • both libraries are widely available on many platforms.

Building and installing ReadOSM is straightforward:

./configure
make
make install

Linking ReadOSM to your own code is usually simple:

gcc my_program.c -o my_program -lreadosm

On some systems you may have to provide a slightly more complex arrangement:

gcc -I/usr/local/include my_program.c -o my_program \
  -L/usr/local/lib -lreadosm -lexpat -lz

ReadOSM also provides pkg-config support, so you can also do:

gcc `pkg-config --cflags readosm` my_program.c -o my_program `pkg-config --libs readosm`

I originally developed ReadOSM simply in order to allow the SpatiaLite's own CLI tools to acquire both OSM .osm and .pbf files indifferently. Anyway I feel that supporting OSM files import/parsing in a simple and easy way could be useful to many other developers, so I quickly decided to implement all this stuff as a self-standing library.

ReadOSM is licensed under the MPL tri-license terms: you are free to choose the best-fit license between:

  • the MPL 1.1
  • the GPL v2.0 or any subsequent version
  • the LGPL v2.1 or any subsequent version

Enjoy, and happy coding