Routing on OpenStreetMap Data

not perfect but possible ...

Version 4.2.30 released!

Preview
osm2po recommends this software...


PostgreSQL


PostGIS


pgRouting


Quantum GIS

created with XMind

osm2po-core (FreeWare)
  • osm2po is both, a converter and a routing engine.
  • osm2po's converter parses OpenStreetMap's XML-Data and makes it routable.
  • osm2po is able to convert large sets like europe.osm
  • osm2po generates sql files for PostGIS, compatible with pgRouting and Quantum GIS.
  • osm2po creates compact topology/graph files for the integrated routing engine.
  • osm2po's routing handles most of OSM's turning restrictions even on large data sets.
  • osm2po contains a simple HTTP routing server.
  • osm2po runs under Windows, Unix and Mac. Just make sure you have Java 6+ installed.
  • osm2po does not depend on foreign Java libraries.
  • osm2po's core is just one file. No installation is needed.

Licence
You are free to make copies, give exact copies of the original to anyone, distribute it in its unmodified form via electronic means. You may not reverse engineer, de-compile or disassemble it, rent, lease, lend or sell it. This software is provided 'AS IS', without warranty of any kind, so use it at your own risk.


osm2po-plugins (OpenSource)
  • Adds some more writers.
  • Enables osm2po to read from bz2 and pbf
osm2po 4.2.30 Download Bundles osm2po-core.jar, osm2po-plugins.jar and the german documentation (PDF).
An english translation is planned for Dec. 2011.
Some Release Notes:
  • The osm2po-routing now contains a Driving-Distance, an AStar and an experimental Travelling-Salesman. Therefore I had to change some interfaces in the routing library. Hence, if you are running osm2po-routing as standalone, contact me for further infos.
    I also had to change the format of one generated routing file. So don't use older g*.2po files. To make it compatible, just convert it again with the cmd=g parameter.
  • The osm2po-converter for PostGIS/pgRouting has not been changed. However, found some minor bugs and fixed them.
  • I've changed some default settings in the osm2po.config file. Most important: I've renumbered the Class-IDs for Streets. So be careful, if things depend on these defaults.
  • An experimental but powerful feature is osm2po's new GeoJson support. Just start the osm2po-Service and directly visualize a route in QuantumGis.
osm2po 4.1.9 Download Bundles osm2po-core.jar, osm2po-plugins.jar and the german documentation (PDF).
OpenStreetMap
entire planet as bz2 or pbf (search for planet-latest)
Geofabrik
extracts as bz2 or pbf
Cloudmade
extracts as bz2 or splitted bz2 (concat first)
Date Topic Description
2011-11-21 Version 4.2.30 released I hate Internet Explorer!
Finally osm2po is compatible with IE < 9 again.
For the one person who already downloaded 4.2.29: Please excuse.
2011-11-20 New Version 4.2.29 released
2011-09-20 OpenLayers 2.11 Problem solved Because this only affects the routing-demo and not the conversion part, I'm not going to release a new version for this fix. However, If you need it now, please contact me via email so I can send you my current version.
2011-09-17 OpenLayers-Bug There is a bug in the new OpenLayers-API which is automatically included in the osm2po-Demo. The Bug is described here.
I reported this behavior to the OpenLayers Forum.
I am not going to code a workaround.
I hope they will fix it soon.
2011-08-18 More Samples
  • I added some more samples to this page.
2011-08-15 4.1.9 released
  • Routes over the entire planet.
2011-08-04 4.1.6 released
  • Treats roundabouts as implicit oneways if not tagged otherwise.
  • Version 3.1 has been removed from the download page.
2011-07-23 4.1.0 released
  • Version is rewritten from scratch and not compatible with 3.x anymore.
2011-06-01 3.2.0 released
  • Reads from StdIn if no file name is given.
  • Plugin's PBF-Parser BugFix (crosby.binary) for files greater than 4 Gig (e.g. europe.osm.pbf)
About:

Here are some successful calls in order to convert OSM-Data to postGIS/pgRouting. These samples also start the osm2po-Service. If you are not interested in the latter, add the parameter cmd=c to each call. But this will not generate the native routing files g*.2po. For more information about the cmd Parameter read the Doc/Pdf. Sorry, it's still not in english, but I hope you can translate it somehow, or at least get an idea of some important parameters such as cmd or tileSize.

System RAM Data Source Command Ways Unresolved
32 Bit 1 Gig Hamburg 08/2011 Geofabrik java -jar osm2po-xxx.jar prefix=hh http://download.geofabrik.de/osm/europe/germany/hamburg.osm.pbf 29 K 0
32 Bit 1 Gig Germany 05/2011 Geofabrik java -Xmx640m -jar osm2po-core-4.jar prefix=de tileSize=10x10,0.5 germany.osm.pbf 2.6 M 0
32 Bit 2 Gig Germany 05/2011 Geofabrik java -Xmx1408m -jar osm2po-xxx.jar prefix=de tileSize=x,c http://download.geofabrik.de/osm/europe/germany.osm.pbf 2.6 M 0
32 Bit 2 Gig Europe 05/2011 Geofabrik java -Xmx1408m -jar osm2po-xxx.jar prefix=eu tileSize=10x10,1,c http://download.geofabrik.de/osm/europe.osm.pbf 11.6 M 23
64 Bit 4 Gig Europe 08/2011 Geofabrik java -Xmx3g -jar osm2po-xxx.jar prefix=eu tileSize=15x15,1,c europe.osm.pbf 12.6 M 3
64 Bit 8 Gig Europe 08/2011 Geofabrik java -Xmx6g -jar osm2po-xxx.jar prefix=eu tileSize=x,c europe.osm.pbf 12.6 M 0
64 Bit 8 Gig USA 08/2011 Cloudmade java -Xmx6g -jar osm2po-xxx.jar prefix=us tileSize=45x45,1,c united_states.osm.bz2 14.5 M 1528
(Cloudmade problem?)
64 Bit 8 Gig Planet 08/2011 OSM java -Xmx6g -jar osm2po-xxx.jar prefix=pl tileSize=45x45,1,c http://planet.openstreetmap.org/pbf-experimental/planet-latest.osm.pbf 35.5 M 7

Note:

(Number of) ways include
highway=primary, highway=primary_link, highway=secondary, highway=secondary_link, highway=tertiary, highway=motorway, highway=motorway_link, highway=trunk, highway=trunk_link, highway=residential, highway=road, highway=unclassified, highway=service, route=ferry, railway=rail (if shuttle_train)

Issue Description Tip or Code
Java Standalone Routing
package de.cm.osm2po.test;

import java.io.File;
import java.util.Properties;

import de.cm.osm2po.routing.DefaultRouter;
import de.cm.osm2po.routing.Graph;
import de.cm.osm2po.routing.SingleTargetRouter;
import de.cm.osm2po.routing.Graph.SegmentHolder;

public class StandAloneRouting {

 public static void main(String[] args) throws Exception {

  File dir = new File("./hh"); // path to g*.2po Files
  Graph graph = new Graph(dir); // CTOR loads graph into memory
  SingleTargetRouter router = new DefaultRouter(); // Dijkstra with specials

  // Somewhere in Hamburg
  int sourceId = graph.findClosestVertexId(53.5f, 10.0f);
  int targetId = graph.findClosestVertexId(53.4f, 10.1f);

  // Possible params for DefaultRouter
  Properties params = new Properties();
  params.put("findShortestPath", false);
  params.put("ignoreRestrictions", false);
  params.put("ignoreOneWays", false);
  params.put("heuristicFactor", "1.0"); // 0.0 Dijkstra, 1.0 good A*

  router.traverse(graph, sourceId, targetId, Float.MAX_VALUE, params);

  if (router.isVisited(targetId)) { // Found!
   int[] path = router.makePath(targetId);
   for (int i = 0; i < path.length; i++) {
    SegmentHolder sh = graph.lookupSegment(path[i]);
    int segId = sh.getConstPart().getId();
    String segName = sh.getVarPart().getName().toString();
    System.out.println(segId + "\t" + segName);
   }
  }

  graph.close();
 }

}

QuantumGIS osm2po as GeoJson-Layer
It is possible to calculate a route in osm2po,
output the result as GeoJson and to add it as
a layer in QuantumGIS.
  • Make sure you have converted the osm2po graph
    files with cmd=g and have started
    osm2po with cmd=r (Service)
  • Instead of opening the WebGUI in your Browser
    with e.g. http://localhost:8888/Osm2poService
    add these Parameters to the address above:
    ?cmd=fr&source=100&target=1000&format=geojson
  • The Browser should show you the routing result
    as plain text in geojson format (UTF8).
  • If this works, copy the complete address,
    open your QuantumGIS and add the layer under
    Menu-Layers-Add_VectorLayer
    A Dialog opens. Set the protocol to
    GeoJSON and the encoding to UTF8
    Finally copy the address into the URI Field and
    click Open
osm2po Routing How to speed it up
osm2po's DefaultRouter's core is a "for all purposes" solution.
It's an Dijkstra with Heuristic. Ergo it's an AStar, too.
It can toggle between Shortest- and Fastest-Path and can switch between ignoring oneways or not or ignoring turn restrictions or not.
It also handles Driving-Distance.
Most of those corresponding parameters are not part of the interfaces and are driven by named properties.
The basic idea behind all this is to let other people implement their personal routing-algo, which will improve its performance at least by reducing the amount of if-then-else-Statements.
Another aspect is the fact that Java is per se slower then C.
So please do never compare speed between David and Goliath.

But there is one thing you can do to make it dramatically faster:
The Routing is a two step process.
First the route itself will be calculated. This takes place in memory.
If the route is successfully created a second step reconstructs the geometries.
These geometries are usually looked up from HardDisk, namely from the gs_var.2po and gs_const.2po files.
This may be very slow on long travels.
But it is also possible to cache these files into memory on startup.
To do so, set sp.cache.segments=true
or modify the corresponding line in the osm2po.config

Responsible for the content of this website:

Carsten Moeller
Dingstaette 12
D-25421 Pinneberg
Germany

email

Disclaimer:
Despite careful control of the contents, I do not assume any liability for the content of any sites linked to from this Web site. I do not control sites linked to and assume no responsibility for their content. Solely the operators of sites linked to are responsible for the content of said sites.