I am creating a Bus arrival prediction system using Java and Postgres.There is fixed route for each bus, so we are storing whole driving route as LineString in postgres.
There are 3 bus stoppage, and each bus stop lat lon is also stored as LineString in routes table. There is one more table which have stoppage name and lat lon details.
stoppage_details Table
Stoppage 1 - lat1,lon1
Stoppage 2 - lat2,lon2
Stoppage 3 - lat3,lon3
I am looking Postgres function to solve below problem.
- How can I get total distance(660m) of route using LineString(Start point lat lon and End point lat lon).
- There is GPS System installed in each bus which send data at every 30 sec.I am using ST_ClosestPoint function to find nearest vertex from LineString. How can I find the distance between vertex and next and previous stoppage using LineString.
- Or Can someone suggest any other approach to solve above problem.