An osm2po Quickstart

This post covers the necessary steps to use osm2po on Windows. Osm2po is both, a converter and a routing engine. It parses OpenStreetMap data and makes it routable. While osm2pgrouting seems to be limited by the amount of memory that is available on your system, osm2po is able to convert large sets like europe.osm. It generates SQL Insert scripts for PostGIS, compatible with pgRouting and Quantum GIS.

To get started, download osm2po and an OSM binary file like e.g. austria.osm.pbf. Extract osm2po and you’ll find the .jar file together with the tool’s documentation (German only though).

That’s all, you’re ready!

To load your network from the .pbf run:

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"

Once finished, you should be able to test the results by visiting http://localhost:8888/Osm2poService in your browser:

A shortest path using osm2po routing

Next up: How to use osm2po with pgRouting.

22 comments
  1. olivier said:

    Hi!

    When I launch the program I have this following message:

    Caused by: java.lang.ClassNotFoundException: osm2po-core-4.3.8-signed.jar
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: osm2po-core-4.3.8-signed.jar. Program will exit.

    Have you any tip to solve it? I have to restart the OS?

    Regards,

    Thanks

    Olivier R.

    • underdark said:

      Do you have Java Runtime installed? Please contact the author of osm2po for support.
      Best wishes,

      • olivier said:

        Sorry I have forgotten the parameter -jar .

        Thanks

  2. Loïc said:

    Hello,
    Thanks for this very nice post.
    However, i am not able to load, the network,
    i have downloaded the osm2po program and austria.osm.pbf file and put them on the C: drive.
    Then i try to run this :
    C:\osm2po-4.4.4a\osm2po-core-4.4.4a-signed.jar prefix=at “C:\osm2po-4.4.4a\austria.osm.pbf” but nothing happens.
    i also have installed postgresql 9.1 and postgis 2.0.

    Do you know if there is some anything to fix my problem ?
    thanks a lot.

    Best wishes,

    Loïc

    • You need to run the .jar with “java -jar” prepended:

      java -jar osm2po-core-4.2.30-signed.jar prefix=at ….

      Also, I’m not sure if osm2po is PostGIS2 compatible. I only tested with 1.5

  3. Loïc said:

    Hello,
    I tried with “java -jar” prepended and postgre 8.3/postgis 4.2.30 :
    java -jar osm2po-core-4.4.4a-signed.jar prefix=at “C:/osm2po-4.4.4a/hamburg.osm.pbf

    Somebody from a french gis community tried to help me and told me postgre is not necessary to access http://localhost:8888/Osm2poService when you run the line.

    My problem is when i run the command line (java -jar osm2po-core-4.4.4a-signed.jar prefix=at “C:/osm2po-4.4.4a/hamburg.osm.pbf) nothing is happening. There is only a windows openning but she’s also immidiately closing so i am not able to read the message.
    I think there is a problem when i run the line since i can not access http://localhost:8888/Osm2poService.

    Could you tell me if this line is supposed to start the local server ?
    Do you know if i need to configure anything before starting this line ?
    (I tried under both windows xp and windows 7)
    Maybe the problem come from windows. The french person trying to help is using mac OS X and has not any problem.

    thanks a lot.

    Best wishes,

    Loïc

    /hamburg.osm.pbf

    • Hi Loic! Yes, the instructions above should should start the server without further configurations. Judging from the command you posted, I can make out two potential problems: 1) the use of / instead of \ in the pbf path and 2) the lacking end “.

  4. Loïc said:

    hello,
    Thank you very much for your help.
    I tried both of your advices but without success… i still have a windows openning and immediately closing when i run the line so i guess the osm2po server is not starting.

    I have sent an email to Carsten Moeller (osm2po creator) asking for help. I keep you informed of his reply.

  5. Emil Zegers said:

    Hi Loïc,

    Have you edited the osm2po.config file? I think the service settings are commented by default when you download osm2po. So you need to remove the # in the following lines first:

    # service.domain = localhost
    # service.port = 8888

  6. Caleb said:

    Hi!

    Im just writting to say that I followed your tutorial and everything JUST WORKED!!! I was like O.o really? First time ever that I’m working with some spatial tools and thing just worked!!

    So thank God for letting me find you! And thank you for this awesome tutorial!

    • Now that’s great to hear. Thanks Caleb!

  7. underdark,
    i’m am totally new to this technology, so these may be stupid questions but please bear with me. I’ve downloaded all of the components necessary as stated in this tutorial, but I’m getting hung up on “loading the network from the .pbf” and testing the results in the browser. Are there any more steps that could help me? Where do I “run” the “C:\…”? Do I just use the Windows Run dialog box? Just looking for a little more direction. Thanks!

    • You can run that line from windows command line. In the run dialog box, simply enter cmd and the command line will appear.

  8. How do I make this steps in Ubuntu 12.04?

    • osm2po is written in Java so it works exactly same in Ubuntu.

  9. Zupo Llask said:

    Hi Anita!
    First of all I want to congratulate you for the great contents you create here at your blog, they are very helpful! :-)
    Recently I’ve started playing with OSM2PO and pgRouting but I’ve stumbled upon a weird problem which I’m not really sure where it comes from…
    I’ve installed OSM2PO on Ubuntu, with no errors, and I’ve also imported latest Portuguese data from Geofabrik, also with no errors at all. When http://localhost:8888/Osm2poService started running, I’ve tried a very simple routing from 40.64013,-8.61054 to 40.64021,-8.61112 and get a “no routing found”-like alert box. If you check http://goo.gl/maps/k6qyr and http://osrm.at/1KY you’ll see what the result should be.
    I’ve detected this problem because while trying routings between other points, I found some routes really strange (not very optimized) and finally I’m near to the conclusion that for some reason there are some ways missing in my OSM data.
    I’m using OSM2PO v4.5.25.
    What do you think about this?
    Thank you very much for your help! :-)

  10. Zupo Llask said:

    Hi Anita!
    Thanks for the quick feedback! ;-)

  11. Please contact the author of osm2po with support questions.