OSM routing, A*, cycle-filtered, python

The program

Source code (python) and history

Input comes from an *.osm file

Parsed using SAX

Filters for roads which can be cycled. Aware of one-way roads, and assumes that cyclists care about them

Routed using A*, for least distance

300 lines of python, including outputs to image and OSM file

3.2 seconds on 800MHz PC to parse london.osm (800KB), do the routing, and generate the image

The picture

Starting at the junction of Charlotte street and Tottenham street in London

White is the start point. Yellow is the end point

Grey lines are routes that were considered. Blue dots are nodes that were considered.

Green dots are nodes that were still in the queue for testing when the solution was found (note: A* guarantees that the route found is better than any possible route from these green dots)

(note: A* guarantees that the route found is better than any possible route from these green dots) Green line and light-green nodes indicate the final route

Download that route as an OSM file

Outputs

Sample OSM route from route

Sample GPX route (paste GPX files into a route viewer to see them overlaid on a map)

Other samples

Across Lyon

6.6 seconds to parse and route a 2.3MB OSM file

Another route in Lyon

We've had to allow primary roads to be used, because otherwise you can't get across the river at all.

But here, it's actually following a big road for lots of the journey, illustrating why it needs weightings to be applied to the different sort of route rather than just 'usable/unusable'

More benchmarks, more uses

karouf reports that it took 1min11 to route over 100km using a 146MB osm file

...also that it routed 700km in 3min40

GUI