I need to calculate stop times of bus lines (extrapolation)

I have:

  1. Shapefile with all stops
  2. Shapefile with control points where bus time was taken
  3. Shapefile with all bus routes
  4. CSV file with times in first stops on the route, final stops and control points where time was taken.

All of the Shapefiles have an attribute "route number" which identifies to which transport route they refer.

I need to find a tool (and procedure) that helps me extrapolate times in each of the stop on the route, using the departure time, arrival time and times at control points on the route (which are not stops). I suppose I actually need to calculate distances first and then times based on those distances.

I am unix user so OS tools would be preferable

Any suggestion how to crack this? Attributes described below.

Stops shapefile

Description: Locations of bus stops


Cod_ubic_p -    stop location
Code_variant -  bus line (referenced in *Bus* shp file)       
Ordinal -   order corresponding to the stop in the journey of the variant (bus line)

control_points shapefile

Description: Locations of control points


Cod_ubic_c -    control point code
Code_variant -  bus line type (referenced in Bus_lines)
Ordinal  -  order of given control point in the path of the variant

(bus line) Desc_locat - Description of Control Point location

Bus_lines shapefile

Description: Routes of bus lines


Cod_line -      Transportation line code
Desc_line -     Description of the transport line (eg 112, D16, etc)
Ordinal -   Correlative number of the sub-line of the line
Code_subline -  Code of the transportation sub-line
Subline Desc -      Description of the sub-line
Cod_variant -   Code of the route (to link with *Stops* shp)
Desc_variant -      Type (Variant) description (A = Ascending, D = descending)

csv sheet Timetables

Description: Timetables


COD_LINE -  Transportation line code
CODE_DAY_TYPE -     Code for the day of the week
LEAVES_FROM -   Origin of the bus route
DEPARTURE -     Depature time
DESTINATION -   Destination of bus route
ARRIVAL -       Arrival time
DESC_LOCAT -    Description of Control Point (Stop) location
COD_UBIC_C -    control point code (referenced in *control_points* shp file)
TIME    -   Time at control point location
ORDINAL -   Correlative number of the sub-line of the line
DESC_VARIANT -  Type (Variant) description (A = Ascending, D = descending)
  • 2
    So you want to answer the question "How much time in total has the bus spent standing still at the bus stops along its route?" – underdark Jul 27 '11 at 14:41
  • No, I want to calculate times at which it arrives to every stop along its route (basically ignoring the standing time - assuming it is zero). And I want to do this for every bus on approx 500 bus lines. – Karel Jul 27 '11 at 15:19
  • Not sure that OpenTripPlanner has tools to extrapolate times, but you might want to connect with their developer team. I imagine they must be doing similar extrapolations. opentripplanner.com/learn – RyanKDalton Jul 27 '11 at 17:21
  • Thanks Ryan, I don't think that OTP can do this (I am pretty sure actually) but probably a good place to ask anyway. – Karel Jul 27 '11 at 17:40

I don't know of any tool that will to this out-of-the box. But I'd give it a try with PostGIS.

After loading all four files into the database, you can reference the stops and control points along the corresponding route line geometries using ST_Line_Locate_Point(). This way, you'll have the information necessary to calculate distances between successive control points and their location relative to the stops.

Assuming that buses stop for 0 seconds and drive a constant speed between stops, you can use simple linear interpolation to calculate arrival time at the a stop based on time difference and difference in distance along route between control points.

  • Thanks Underdark, this will get me going. I also got some good suggestions from fTools author on using Qgis feature Vector > Analysis Tools > Distance Matrix tool to compute a distance matrix. Cheers – Karel Jul 28 '11 at 11:11

Your assumption is that the buses move at a constant speed between control points but not along the entire route, right?

If so, this is a classic linear referencing problem using time as your measure (m-value). I know exactly how to pull this off in ArcGIS, but I am not sure what open source geo tool does this best.

Essentially you need to use a polyline with measures collection (PolylineM) and then carry out route calibration using your control points (with your time stamps as your m values).

Once you have done this, all you need to do query the m-value at each stop location and you will have the arrival time at each stop. So, that is the basic workflow. Anyone have an idea of how you carry this out with OS tools?

Apparently the exact functionality that I am talking about is not available in postGIS/OpenGeo stack: http://opengeo.org/technology/postgis/coredevelopment/lrs/

I'll see if I can find anything in GRASS or QGIS, or maybe someone else knows.

  • Yes, that's what I am looking for. Thanks, let me know if you find an os tool which could do this. – Karel Jul 29 '11 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.