Osm2po Part 2 – PgRouting on OSM the Easy Way

This is the follow up post to “An osm2po Quickstart” which covers loading the OSM network into PostGIS and using the result with pgRouting. After parsing the OSM file, e.g.

C:\Users\Anita\temp\osm2po-4.2.30>java -jar osm2po-core-4.2.30-signed.jar prefix=at "C:\Users\Anita\Geodaten\OpenStreetMap Data\austria.osm.pbf"

you should find a folder with the name of the prefix you chose inside the osm2po folder. It contains a log file which in turn provides a command line template for importing the OSM network into PostGIS, e.g.

INFO commandline template: psql -U [username] -d [dbname] -q -f "C:\Users\Anita\temp\osm2po-4.2.30\at\at_2po_4pgr.sql"

Using this template, we can easily import the .sql file into an exiting database. My pgRouting-enabled database is called wien_ogd.

C:\Users\Anita\temp\osm2po-4.2.30\at>psql -U [username] -d wien_ogd -q -f C:\Users\Anita\temp\osm2po-4.2.30\at\at_2po_4pgr.sql

Now, the data is ready for usage in QGIS:

The osm2po table in QGIS

Using “pgRouting Layer” plugin, it’s now straightforward to calculate shortest paths. I had to apply some changes to the plugin code, so please get the latest version from Github.

A shortest path in osm2po network

Using osm2po turned out to be far less painful than I expected and I hope you’ll find this post useful too.

Advertisement

11 thoughts on “Osm2po Part 2 – PgRouting on OSM the Easy Way

  1. well this is awesome i have downloaded osm2po for a long time but i don’t know how to configure it on windows well mam can you tell me is this a terminal command C:\Users\Anita\temp\osm2po-4.2.30>java -jar osm2po-core-4.2.30-signed.jar prefix=at “C:\Users\Anita\Geodaten\OpenStreetMap Data\austria.osm.pbf”

  2. I’ve been wanting to get around to importing OSM into pgRouting for a while but just never invested the time. Your tutorial couldn’t have made it any easier! Thanks for all the great work.

  3. Hi
    I need your help if you could please explain this , as i am really close to loading osm data in pg Routhing.

    I need to load osm road data using pgRouting and display on openlayer and show the start and end point and give routing suggestions. I have data in .osm format (lets call it sample.osm)
    I would appreciate if you could tell me step by step process for getting the data to postGIS to shortest path search for windows. I have read most of the blog and tutorials but still could not figure out.

    I really appreciate you time and effort.

    Thanks

    Mehul

    • It’s all covered in my posts. What exactly is causing you troubles? A step-by-step guide for the whole process would be far out of scope of a comment. If you can tell me where you are stuck, I’ll try to help.

  4. This is great..just what i was looking for..but i have a question..to make pgrouting do you work with polygons or lines?..It may sound foolish but it’s my doubt..

  5. It would be great to have your tutorials for google maps styling of osm data updated for this osm2po imported data. Do you have some rules and qgs files you could share? Thanks!

  6. Hi,

    Many thanks for the tutorial, great job!

    I have downloaded osm2po and I have managed to import some osm data without any problem. However, I have noticed that the osm_id column doesn’t contain unique ids. That column lists basically the road ids right? So, my question is, is there any way so we can change that and eventually end up with a table that holds records for unique osm_ids only?

    Cheers

    • osm2po creates a unique “id” field. I assume “osm_ids” contains the original IDs as found in the OSM file. Why would you want to change them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s