Tools to query data from GTFS schedules using PouchDB databases.
Most of the functions follow a pattern where the function is called like
In this example, the call to
getAgency(agencyDB) returns a function, which
is then immediately called with the
id parameter. The second function returns
a promise, which resolves when the information is loaded from a database.
In general, databases are passed inside the first function, and ids are passed in the second.
Gets an agency from the schedule, or the first listed agency if no ID is used. Since most schedules have only 1 agency without an agency_id property, this function will return that agency.
Gets a specific calendar date object from the database
- date: Either a moment, or a string in the YYYYMMDD format.
Returns every exception for the given service ID
Returns exceptions for the following month, or a custom duration instead.
- duration: A moment duration, defaults to 1 month.
- now: The current time. Can be overriden.
Get the dates of service for a given calendar entry as a set of integers. 0 represents Sunday, 1 is Monday, etc.
calendarEntryToDays by looking up the calendar entry for a service ID
Returns a string representing days of service, such as 'Daily' or 'Mon - Fri'
- days: Set of days in the week that are serviced by the route
- mode: Determins the format of the returned day names.
- normal: Sunday, Monday, ...
- short: Sun, Mon, ...
- min: Su, Mo, ...
Returns the name string from the route. route_long_name is preferred, and route_short_name is used as a fallback
Get a route based on its
route_id, which is different from the
used in the database
Get every single route
Get every route that connects to a given stop
Returns all days of the week that a route is active on
Returns a specific point in a shape
Returns every point in a shape, sorted by their shape_pt_sequence
Converts a series of shape point into a GeoJSON line string. The shape array should be sorted and all belong to the same shape_id
Gets a stop time from the database
Get the stop times associated with a trip, sorted by stop_sequence. Throws 404 error if no schedule is found.
Returns stop times associated to a stop
Returns the first and last stop in a trip's schedule. Throws if there is no schedule for the trip.
Returns the next stop that will be reached based on a list of stop times. Throws if the list is empty.
Returns a stop from the database
Looks up the address for a stop using Google Reverse Geocoding
- apiKey: API key for Google API
Returns the nearest stop to some position. Optionally, a maximum distance from the position can be specified. Maximum distance is set in the same units as latitude and longitude.
Returns the stop as a GeoJSON point.
Returns every stop as a GeoJSON point. No properties are set on the resulting features, instead only the position and id are set. Internally, the stop id and position are indexed, so these points can be generated without loading the entire stop database.
- bounds: If set, the stops returned are limited to a certain area.
Get a trip based on its
trip_id, which is different from the
used in the database. Providing a
route_id will speed up the lookup.
Returns the name of the trip. Uses trip_short_name or trip_headsign, and returns an empty string if neither are avaliable
Get every single trip that is a child of a route
Finds the earliest and latest time in the trip's schedule and returns an array representing a range. If the schedule is empty, null is returned instead.
Gets the trip that is currently running in a route. If none are running, the first trip is returned instead. If some are running, the earliest current trip is returned.
Gets the previous and following trips in this trip's route; that is, the trip that took place immediately before and immediately after.
GTFS object interfaces
Typescript interfaces are also exported under