I built this webapp a couple of weeks ago. It was a fun weekend project. I arrived at the idea when I was travelling in the Metro and was unable to find an app that would give me proper directions, like which train U needed to board, headed to which station, or if I had other route options etc. Or I would have to fire up data-hungry Google Maps when I had less data available and was on a slow connection.
The app is available at http://thezillion.github.io/metrenq
The app does not have great aesthetics by the way.
Just enter the boarding and deboarding stations and it will list the number of routes, ranking routes by number of stations, and also displaying number of interchanges for every route.
How I built it
I used jQuery and the awesome Select2 library.
All data is stored in three JS objects: stations, lines, and ipoints.
Only the stations object and a part of the lines object are loaded from the server. The other three data objects are populated using the process_data function.
The stations object contains basic station data: the station name, lines it loes on, and station number. This number is the way of representing the station throughout the program.
The lines object contains line data: stations on each line in the correct order and also tells which line it intersects with, and at which station.
The ipoints object is a fast access object meant to list all the ipoints for every line.
Ipoint: Short for intersectiom point, an ipoint is the station where two lines cross each other.
One-interchange relationship (OIR): Two stations are in an OIR if we can go from one to the other by interchanging only once.
The task is to find all possible routes between two points (stations) on the map. The stations may be:
- on the same line
- in an OIR
- connected through more than one interchange
The first two cases are simple. The third case is a bit complex. I’ll explain the algorithm using three examples signifying each of the three cases.
In the second case, I simply find a common interchange point for the two stations based on the lines of the two stations.
In the third case, I find the ipoints on the current station’s line(s) and recursively try to find an OIR between the ipoint and destination station. If an OIR is not found, I again find the ipoints for this station and repeat the process.
I’m still working on the app. I plan on making the displayed information more detailed, plus improving the aesthetics.
Hope you like it! http://thezillion.github.io/metrenq/
Delhi Metro Map
This is what the Delhi Metro map looks like. It’s still growing and getting denser.