osm2pgrouting data converter

This tool makes it easy to import OpenStreetMap? data and use it with pgRouting. It creates topology automatically and creates tables for feature types and road classes. osm2pgrouting was primarily written by Daniel Wendt and is now hosted on the pgRouting project site:

How to install (Ubuntu 8.04)

Check out the latest version from SVN repository:

svn checkout osm2pgrouting

Required packages/libraries:

1. PostgreSQL 2. PostGIS 3. pgRouting 4. Boost library 5. Expat library 6. libpq library

Note: if you already compiled pgRouting point 1. to 4. should already be installed.

Then compile

cd osm2pgrouting

How to use

1. First you need to create a database and add PostGIS and pgRouting functions:

createdb -U postgres osm
createlang -U postgres plpgsql osm

psql -U postgres -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql osm
psql -U postgres -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql osm

psql -U postgres -f /usr/share/postlbs/routing_core.sql osm
psql -U postgres -f /usr/share/postlbs/routing_core_wrappers.sql osm
psql -U postgres -f /usr/share/postlbs/routing_topology.sql osm

2. You can define the features and attributes to be imported from the OpenStreetMap? XML file in the configuration file (default: mapconfig.xml)

3. Open a terminal window and run osm2pgrouting with the following paramters

./osm2pgrouting -file /home/foss4g/capetown_20080829.osm \
				-conf mapconfig.xml \
				-dbname osm \
				-user postgres \

Other available parameters are:

 * required: 
	-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
 * optional:
	-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

4. Connect to your database and see the tables that have been created

psql -U postgres osm
                 List of relations
 Schema |        Name         |   Type   |  Owner   
 public | classes             | table    | postgres
 public | geometry_columns    | table    | postgres
 public | nodes               | table    | postgres
 public | spatial_ref_sys     | table    | postgres
 public | types               | table    | postgres
 public | vertices_tmp        | table    | postgres
 public | vertices_tmp_id_seq | sequence | postgres
 public | ways                | table    | postgres
(8 rows)

Note: If tables are missing you might have forgotten to add PostGIS or pgRouting functions to your database.

Let's do some more advanced routing with those extra information about road types and road classes.