Table Of Contents

Previous topic

OSM2PostGIS - Import OSM data to PostGIS

Next topic

pgRouting Gallery

Make a Donation

Support pgRouting with some donation! Read more about how your donation will help the project.


osm2pgrouting - Import OSM data into pgRouting Database


osm2pgrouting currently doesn’t support anymore pgRouting v1.x but requires pgRouting 2.0 or higher.

Easily import OpenStreetMap data into a pgRouting database using osm2pgrouting tool.

osm2pgrouting was primarily written by Daniel Wendt and is now hosted on the pgRouting project site.


  • Uses XML configuration file to select road types and classes to import
  • Creates types and classes tables, which can help to create sophisticated cost functions


If you already [wiki:1.x/InstallationManual installed pgRouting], you should have all required libraries/packages.

  • PostgreSQL
  • PostGIS
  • pgRouting

Currently osm2pgrouting is only tested on Linux distributions.

How to install

Download the latest version from osm2pgrouting GitHub repository and extract the file:

Then compile:

cd /path/to/osm2pgrouting

If you get an error like

src/Export2DB.h:25:22: error: libpq-fe.h: Datei oder Verzeichnis nicht gefunden
src/Export2DB.h:84: error: ISO C++ forbids declaration of ‘PGconn’ with no type
src/Export2DB.h:84: error: expected ‘;’ before ‘*’ token
src/Export2DB.cpp: In constructor ‘Export2DB::Export2DB(std::string,
std::string, std::string, std::string, std::string)’:
... etc etc.

just change src/Export2DB.h and set the path to libpq-fe.h statically.

How to use

Start the program like this:

./osm2pgrouting -file your-OSM-XML-File.osm \
                                -conf mapconfig.xml \
                                -dbname routing \
                                -user postgres \

all available parameters are:

-file <file>  -- name of your osm xml file
-dbname <dbname> -- name of your database
-user <user> -- name of the user, which have write access to the database
-conf <file> -- name of your configuration xml file
-host <host>  -- host of your postgresql database (default:
-port <port> -- port of your database (default: 5432)
-passwd <passwd> --  password for database access
-clean -- drop peviously created tables


There was a patch attached to some Wiki page on the previous TRAC website. You can download the patch from here: osm2pgrouting.patch