I want to track and visualize the progress of a bus, as follows:
- I have the coordinates of each station
- as well as the coordinates of the bus, updated every 10 seconds
The information is stored in Postgres, as
float tuples, without any awareness of street topology, or other GIS-related metadata. At the moment I have a naive implementation that calculates the "as the crow flies" distance between 2 points (the bus and the next expected station). This allows me to build a rough progress-bar, but due to the way the streets are laid out in certain parts of the city, sometimes these estimations are... very wrong.
My understanding is that the proper way to deal with this is to rely on "map-matching", which will do a "snap to road" transformation of the coordinates of the bus. This, in turn, will allow me to see what distance was covered, as if the entire route is a straight line:
However, I do not have the GIS experience that would give me the confidence that (1) I am on the right track and that (2) I chose the path of minimum resistance.
What are the best practices in addressing this problem?
Update: the current software is a pure Python program that performs these calculations. No GIS tools are involved at all, though I suspect that the problem at hand is probably a typical scenario for them. I would prefer a solution that uses free/libre open source software, which can be integrated into existing systems, a Python API would be a plus.