Osmium/Quick Start

From OpenStreetMap Wiki
Jump to: navigation, search

Install Prerequisites

Look into the README file for a list of prerequisites and install them. Some are only needed for certain functionality, so if you don't have all of them, some parts of Osmium might still work. You'll also need git and a C++ compiler etc. On Debian/Ubuntu systems you also want to install the programs that allow you to build a Debian package (devscripts, debhelper, fakeroot).

On Debian/Ubuntu you can do this:

# install all dependencies
sudo apt-get update
sudo apt-get install zlib1g-dev libshp-dev libsqlite3-dev \
 libgd2-xpm-dev libexpat1-dev libgeos-dev libgeos++-dev libxml2-dev \
 libsparsehash-dev libv8-dev libicu-dev libgdal1-dev \
 libprotobuf-dev protobuf-compiler devscripts debhelper \
 fakeroot doxygen libboost-dev git-core
# note: git-core might be simply "git" on your distribution.

On openSUSE 12.2:

# add repositories
zypper ar http://download.opensuse.org/repositories/home:/inescid:/language/openSUSE_12.2/ sparsehash-repo
zypper ar http://download.opensuse.org/repositories/Application:/Geo/openSUSE_12.2/ Geo
# install packages
zypper in zlib-devel libshp-devel sqlite3-devel gd-devel \
 libexpat-devel libgeos-devel libxml2-devel sparsehash \
 v8-devel libicu-devel libgdal-devel protobuf-devel boost-devel git-core

Install OSM-binary

For PBF support you need the current version of libosmpbf.

On Debian/Ubuntu:

mkdir libosmpbf
cd libosmpbf
git clone https://github.com/scrosby/OSM-binary.git
cd OSM-binary
debuild -I -us -uc
cd ..
sudo dpkg --install libosmpbf-dev_*.deb

On other systems:

mkdir libosmpbf
cd libosmpbf
git clone https://github.com/scrosby/OSM-binary.git
cd OSM-binary/src
sudo make install

Download Osmium

Currently there are no packages with Osmium available. Get Osmium from Github:

git clone https://github.com/joto/osmium.git
cd osmium

Install headers

As Osmium is a header only library, you'll likely want to install them so that you have access to them from other software that you compile. There is also a dependancy on graphviz, which will list a load of warning if not installed when you install the headers.

sudo apt-get install graphviz
sudo make install

Build Examples

Osmium is a C++ header only library, that means all functionality is in C++ header files. So you don't need to compile it, just compile the application that uses Osmium and #include the files.

Osmium comes with a set of example programs. To compile them:

cd examples

You can now run

./osmium_debug SOME_OSM_FILE

You will see debug output showing each object in the OSM file with its attributes and tags. You can use any kind of OSM file (XML, optionally compressed with gzip or bzip2, or PBF format).

Have a look around the examples directory and try the other example programs. They should give you some ideas what you can do with Osmium and how to do it.

Build Osmjs

You can include Javascript support into your Osmium applications. See the osmjs program on how to do it. For this you need the Google V8 Javascript engine.

To compile osmjs:

cd osmjs

To test this run:

./osmjs -l sparsetable -j js/objects.js SOME_OSM_FILE

It should give you a debug output of all OSM objects in the file. To use the two-pass-version that assembles multipolygons for you:

./osmjs -2 -m -l sparsetable -j js/objects_2pass.js SOME_OSM_FILE

Try the other scripts in the osmjs/js directory. They have short usage instructions in their headers.

Further Reading

See Compiling Osmium for more details about compiling Osmium.