This is a related article of I made my own transfer guide using OpenTrip Planner and GTFS. Tips for creating a transfer information site European Subcontinent Railway using OTP as a Java library.
OpenTripPlanner (OTP) has a web service, and you can use IndexAPI in it to get the registered GTFS data. be able to. However, when using OTP as a library inside the application, how to get the data.
In conclusion, if you look at the source of Index API (org.opentripplanner.index.Index API), it's almost at a glance. Well then, I don't have a body or a lid ...
python
//Get GraphIndex object from Graph object
GraphIndex index = graph.index;
//Get GTFS data from a GraphIndex object
//Get route information
Route r = index.routeForId.get(new FeedScopedId("fid", "tokaido"));
//Get stop information
Stop s = index.stopForId.get(new FeedScopedId("fid", "tokyo"));
//Get trip information
Trip t = index.tripForId.get(new FeedScopedId("fid", "fuji1"));
A combination of Feed ID and ID on GTFS is required to identify each element of GTFS on OTP. OTP, which can import multiple GTFS files, assigns a unique ID to each GTFS file when importing data. This is the Feed ID. (For details, see here) The object that represents the combination of this Feed ID and ID on GTFS is org.opentripplanner.model.FeedScopedId. Create this object and search for the corresponding element using it as a key. The GTFS data is stored in the org.opentripplanner.routing.graph.GraphIndex object, which can be obtained from the index property of the org.opentripplanner.routing.graph.Graph object. The table is as follows.
GTFS file | Corresponding OTP object | GraphIndex properties that can be obtained |
---|---|---|
agency.txt | org.opentripplanner.model.Agency | agenciesForFeedId |
stops.txt | org.opentripplanner.model.Stop | stopForId |
routes.txt | org.opentripplanner.model.Route | routeForId |
trips.txt | org.opentripplanner.model.Trip | tripForId |
Prior to OTP 1.3, GTFS-related metadata used the OneBusAway object of the same name. Although the packages are different, the usage is the same.
Recommended Posts