Optimizing bicycling routes with OpenStreetMap and APIs

(There’s a video version of this article available here, where we also do a deep dive into the code behind it, remember to turn on subtitles):

I’ve started playing with data from OpenStreetMap (OSM). It started with me trying to fetch all the places where I could get free water when moving around Copenhagen, which turned out to be a daunting task, because OSM seems to have a lot of different ways to categorise available water. I’ve identified the following tags to look out for:

Tag Documentation
amenity=drinking_water https://wiki.openstreetmap.org/wiki/Tag:amenity%3Ddrinking_water
man_made=water_tap https://wiki.openstreetmap.org/wiki/Tag:man_made%3Dwater_tap
amenity=water_point https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dwater_point
drinking_water=* https://wiki.openstreetmap.org/wiki/Key:drinking_water

Contributing back to OpenStreetMap #

I soon became interested in contributing back, so I found the Android application called “StreetComplete” that makes it easy to contribute to OpenStreetMap. The app will give you different challenges or missions to complete that will provide more data for OpenStreetMap.

Some call this “data-exercising” where you go out and get exercise and gather data to OpenStreetMap.

I follow a person called Søren on Twitter, with the handle of @neogeografen, and he has been speaking about mapping the surfaces of bicycle paths in Denmark. He shared a map to look up missing surfaces nearby. This is how looks for me in Copenhagen:

Screenshot 2021-08-09 at 18.12.08.png

Biking around and mapping different surfaces #

I wanted to map these as efficiently as possible. I have a bike so the idea was to create the most optimal path between the nodes that are missing data. Luckily it is easy to export the data from Overpass:

Screenshot 2021-08-09 at 18.48.49.png

I found an Optimization API from OpenRouteService that can calculate all sorts of combinations. If you have lots of stops and different drivers with different start and end points it can find the most optimal routes; luckily I don’t need any of that. They also have very generous pricing (free).

Building the script #

So the idea was to build a script that:

The Optimization API has a limit of 50 stops, and Google Maps routing seems to have a limit of 10-15 stops (depending on different sources).

Here’s the HTML output my scripts generates:

Screenshot 2021-08-09 at 20.07.42.png

And when I click the Google Maps route link this is what I see:

Screenshot 2021-08-09 at 20.06.03.png

The code is available here: https://github.com/kaspergrubbe/openroute-routetest

 
7
Kudos
 
7
Kudos

Now read this

Enforcing host parameter usage for URLs in e-mail templates with Hamlcop

At Billetto we have multiple domains for our ticketing website depending on the market, as an example our danish organisation lives at billetto.dk and our swedish counterpart lives at billetto.se. All of our organisations shares the same... Continue →