Till senaste kommentaren
Detta inlägg är gammalt och kan innehålla inaktuell information.

SL Departures v4.0 and GTFS realtime

Is it possible to combine the results from https://www.trafiklab.se/api/trafiklab-apis/sl/departures-4/ with https://opendata.samtrafiken.se/gtfs-rt/sl/VehiclePositions.pb and

* if so does the JourneyDirection in the departures result correspond to the DirectionId in in the VehiclePositions result, i.e. does JourneyDirection represent the static GTFS property trips.txt::direction_id?

* if so how do the JourneyDirection values [0, 1, 2] map onto the DirectionId values [0, 1], there's no concept of unknown direction in trips.txt::direction_id.

BR
Alex

Kommentarer

  • Sorry I just realized that trips.txt::direction_id is optional so that takes care of the non bidirectional mapping problem, but still, is it possible to combine these two APIs and if so how does the JourneyDirection map onto the VehcilePosition DirectionId?
  • Hi Alex!

    These two APIs fetch data from different systems, so the identifiers between the SL Realtime API and the VehiclePositions feed will not match. We recommend to use the GTFS Static data instead, which you can combine with existing solutions (such as OpenTripPlanner) to get an API, or you can use your own script. For how you can convert a GTFS feed to a timetable, please see these articles and examples:

    https://www.trafiklab.se/docs/using-trafiklab-data/using-gtfs-files/static-gtfs-files/
    https://cran.r-project.org/web/packages/tidytransit/vignettes/timetable.html

    If you want to combine the APIs, you will need to map the trip id to a departure from SLs APIs, which can't be done directly. The solution for this would be to lookup the trip id in the static GTFS dataset, obtain the stop_times for that trip, and find the stop_time at the stop you are looking at in the SL file.

    Alternatively, you could find the matching stop in the GTFS file, find all trips connected to that stop, and then search the vehicle position data for vehicles linked to those trips.

    I hope this helps you in the right direction. Feel free to ask if you have further questions.

    Regards,
    Bert

    Bert på Trafiklab

Kommentera eller skriv ett nytt inlägg

Ditt namn och inlägg kan ses av alla. Din e-post visas aldrig publikt.