[JAVA] Get GTFS data from OpenTripPlanner Graph

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.

Introduction

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.

Conclusion

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 ...

Source

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"));

Commentary

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

Get GTFS data from OpenTripPlanner Graph
Get "2-4, 7, 9" from [4, 7, 9, 2, 3]
[IOS] How to get data from DynamoDB
Get weather forecasts from Watson Weather Company Data in simple Java
[IOS14] How to get Data type image data directly from PHPickerViewController?
CData Software Hands-on (Get Twitter data from Java console application)
[Java] Get data from DB using singleton service in Spring (Boot)
How to get and add data from Firebase Firestore in Ruby
Get weather forecasts from Watson Weather Company Data with a simple JSP