Giter VIP home page Giter VIP logo

time2reach's Introduction

image.png

Time To Reach - Transit Travel-time Map

It's a travel-time map for public transit that shows which areas of the city are most accessible by public transit.

I built this while trying to look for housing in Toronto. I found myself going back and forth on Google Maps trying to compare which locations have a shorter commute via transit. I completed this project long after I found a place, but hopefully it helps someone else.

How it works

The app consists of a Rust backend which queries the transit schedule data (in GTFS format) and a React frontend which displays the map and colors each road segment according to how long it takes to reach that segment from the origin.

Generating times to reach for each road

The backend uses heuristics-based BFS search on each trip from the origin. At all stops along that trip (time_to_reach.rs:all_stops_along_trip()), we "disembark" and see what other routes we can take from that stop (time_to_reach.rs:explore_from_point()). For each possible new route, we do the same thing: get on and along all stops, see what other new connections can be made.

There are some heuristics to make each query faster:

  • We only get off a stop if we haven't reached that stop before (or we have reached it before but at a worse time).
  • Rather than using a queue like in traditional BFS, we prioritize exploring train/subway routes first, as they are faster and result in less work.

Rendering the tiles

I used an approach similar to how Google Maps displays traffic congestion (red, yellow, green). I used the Python library OSMnx (download_gpkg.py:generate_geopackage_all_cities) to download road vectors from OpenStreetMaps and loaded them into a PostGIS database.

Using Mapbox's vector tile sources and Expressions feature, I could color these road segments based on their ID:

map.setPaintProperty("transit-layer", "line-color",
    ["get", ["to-string", ["id"]], ["literal", timeToReachData]],
);

timeToReachData converts road segment IDs to a color, based on how long it takes to reach that segment.

Drawing paths

When you hover over any particular point, the app draws the path from the origin. The path shows you which buses or trains to take. We cache the results of the BFS search as a tree of individual vehicle trips. For example, if all destinations require you to take the Line 1 Subway, we only store that trip once. If a trip is a transfer from a previous trip, we store the Id of the parent trip in InProcessTrip.previous_transfer (in_progress_trip.rs).

When you hover over a point, we simply traverse the tree backwards via the previous_transfer pointer until we reach the origin.

This approach requires very little memory to store all the possible trips and their paths from the origin. Since these trips are immutable, we store them inside an Arena to avoid lifetime problems. Since Arenas store trips contiguously, we also don't experience memory fragmentation problems that come with large trees. Freeing the memory of the tree is also incredibly performant, as we just clear the memory of the Arena.

time2reach's People

Contributors

econaxis avatar ng-henry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.