## Inspiration

As regular bikers in Berlin we often encounter dangerous situations in traffic. Research shows that bike usage in cities could be much increased if perceived safety was higher [1]. In Berlin in 2019 alone over 13.000 road accidents occured, every 2 hours a biker had an accident (over 5.000 accidents involved bikers) [2]. 34 accidents were fatal. This why we wanted to create something that increases bike safety in cities, which made us come up with "Gefahrradtour", a portmanteau of "Gefahr" and "Fahrrad" which mean "danger" and "bike" in German.

## What it does

### The app

The app shows you the shortest but also the safest route that helps you avoid dangerous streets and intersections to arrive safely to a destination of your choice. It allows the user to select a starting point and a destination (either by typing the address or clicking on the map) and to choose either the fastest route (very dangerous route) or the safest route (very safe route). Once the route is generated you can see which parts of the route are more dangerous (red color indicates higher number of accidents) and how many accidents happened on that route in total (based 2019 data).

### How routes are computed

To find the route between two coordinates we used the navigable roads dataset in the HERE data layers. Using the tidygraph library in R, the road data was preprocessed into a graph G(V,E), where V represents its sets of nodes and E its set of edges. All road segments represent egdes and all intersections represent nodes. The road graph serves as input into the shortest path algorithm, for which we used the Dijkstra's algorithm [3]. This algorithm outputs the shortest path between two nodes in a graph. It takes into account the edges' weights. If the user selects the "very dangerous route" in the shinyapp, these edge weights are simply the length of each road segment. If "very safe route" is selected, we check how many accidents occured on a road segment and add 300 m to this edge's length for each accident that occured on it. We choose 300 m since this produced the most logical routes with a good balance of route safety and route length. We counted accidents with severe injuries as two accidents and those that lead to a death as three accidents.

## How we built it

The app is built with R Shiny (see the app.R script). For all the mapping functionality, it used the Leaflet package and the theme applied is Bootstrap Sketchy. For the geocoding and reverse geocoding we used the HERE Geocoding and Search API. As explained above the routes are computed using an algorithm to find the shortest path between two points using the navigable roads data set from the HERE data layers.

## Challenges we ran into

We first tried calculating the shortest and safest route using the openstreetmap data and compared it with the HERE data layers navigable roads. The HERE data worked much better since there all edges and nodes where already connected, osm needed much more data cleaning. Also, we ran into problems with shinyapps.io and an outdated GEOS library which forced us to come up with a workaround for one of our essential functions. Additionally, we wanted to included more analysis about correlations between signage and accidents in Berlin, but did not find any immediately applicable results.

## Accomplishments that we're proud of

We are proud that we implement a routing algorithm ourselves which works quite fast. Also, we get usable and realistic results without overcomplicating and overengineering the calculations.

## What we learned

We learned about graph analysis and that there is a very good open source video editor for Macs.

Currently, this demo version of the app is only available for a restricted area of Berlin for which we have data on navigable roads and accidents available. Not all cities will have such robust data on accidents, however the HERE data layers provide some possible avenues to extend Gefahrradtour to these cities. One such example is the information on signage. Within the area covered by the HERE signage data, we see that 70% of accidents involving bicycles occur where there is no traffic signage (within 20 meters), giving some indication that signs help to reduce to accidents.

There would need to be more rigorous analysis to contextualize this (e.g. total sign coverage and traffic volumes), but doing so in a more fleshed-out product would allow for a more flexible application to additional cities with only partial data coverage.

## Sources

[1] https://www.sharetheroad.ca/why-do-people-choose-not-to-cycle--s16209, visited Dec. 5th 2020.

[2] Amt für Statistik Berlin-Brandenburg (2019). Strassenverkehrsunfälle nach Unfallort in Berlin 2019. mt für Statistik Berlin-Brandenburg (visited November 2020).

[3] West, D.B. (1996). Introduction to Graph Theory. Upper Saddle River, N.J.: Prentice Hall.