Help

Publess routes through Dublin? GraphHopper edition.

A long time ago there was a nice blog post

How to walk across Dublin without passing a pub

from Rory and there was even someone who tried this in real life. Now we thought how this would look like today using GraphHopper instead of the manual process described in the post.

It turns out that the whole process is much faster and simpler when using a routing engine. For people with little time you can grab the full sources here. First of all we need the data. Getting all pubs as Geojson today is very easy:

  1. Go to Overpass Turbo
  2. Go to the area of your choice, click on ‘wizard’ and enter ‘amenity=pub’
  3. Click ‘export’ and ‘GeoJSON’

The data looks as follows:

Pub data, Dublin, © OpenStreetMap contributors

Integrating the data in an open source routing engine like GraphHopper is also easy. Just look on how to create a custom weighting here. To avoid expensive operations while routing we convert the polygon or bounding box check into something fast like an ID check, only necessary for longer routes and probably not so much for this example. But we still do so as an example, by getting the nearest GraphHopper entry into the graph from the OSM data and all the surrounding edges via:

QueryResult qr = index.findClosest(lat, lon, EdgeFilter.ALL_EDGES);
EdgeIterator iter = explorer.setBaseNode(qr.getClosestNode());
while (iter.next()) {
  avoidEdgeIds.add(iter.getEdge());
}

Now we can use the set of ‘avoid IDs’ in the weighting method and increase the weighting appropriated:


public double calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) {
  double w = super.calcWeight(edgeState, reverse, prevOrNextEdgeId);
  if (avoidEdgeIds.contains(edgeState.getEdge())) {
    return w * 1000;
  }
  return w;
}

The route with the normal “weighting=fastest” looks like:

Original route through Dublin, © OpenStreetMap contributors

Now, if you followed the installation instruction of the git repo (java, maven and git are required) then you can change the weighting=nopub e.g. in the URL then you’ll get a much longer route of 7.3km instead of 5.8km:

Avoid pubs through Dublin, © OpenStreetMap contributors

Conclusion

The whole center is today a no-go-area. And if you look closely it is even not fully possible to walk through Dublin and completely avoid alcohol and its results. The reason might be better OSM coverage for pubs or just more pubs. But the route only contains a reduced amount of pubs like the Abbey street. Such spots we could notify the user via special instructions, which could be a task for another blog post. Another task could be to persist the edge IDs to avoid importing the pub data on every start.

The first comment on the original blog post was “Good read! Next, can you create a route passing every pub!”. For the solution visit our talk about route optimization with GraphHopper in Berlin at the WhereCamp on 26th November and the solution is just one API call away…