Home

Awesome

pan-european-public-transport

Public transport routing across Europe. Merges data from API endpoints for various regions, in order to get better data than what one endpoint provides.

npm version build status ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

Why?

Why linked open transit data? explains the problem:

When travelling through larger regions or several countries by public transportation, finding out how and when to get to the destination is hard:

  1. People often need to use multiple, regionally limited apps to find out which trains/busses/ferries/etc. are available, because these apps often have imprecise (e.g. regarding accessibility), outdated (e.g. construction work) or just no data whatsoever about other regions. Doing this research across operator boundaries involves a lot of manual work. Essentially the user needs to do the job that computers should do: routing through sub-networks.
  2. When dealing with large distances (e.g. from Norway to France), this routing work becomes almost impossible for humans to do ad-hoc, because there are so many possible connections. Combined with e.g. cancellations & delays, users may never find the optimal connection because of that.
  3. Local, narrow-focused apps are not (as) accessible. They're often developed with a smaller budget, in some languages, without screen reader & offline support, have a bad UX, are only available for some platforms, etc.
  4. Apps built for current mainstream use cases are not future-proof. With the ongoing digitisation, diversification and increased on-demand features, they won't be able to deliver on people's mobility needs. (They barely do that right now.)

How?

For a routing request from A (starting point) to B (destination), it will

  1. fetch results (called journeys) from an endpoint that covers both A and B
  2. identify other endpoints that may have additional data about the parts of the journey (called legs), using
  3. for each leg, try to find the equivalent leg in each endpoint and merge it with the one fetched first

For a departures/arrivals request for a station A, it will

  1. fetch results from the "most local" endpoint that covers A
  2. identify other endpoints that may have additional data
  3. for each arrival/departure, try to find its equivalents in those endpoints and merge them

Note: Right now, this only works with hafas-client@5-compatible API clients.

Compared with the goals specified in Why linked open transit data?, this project can be seen as a "stepping stone" towards them:

Nevertheless, it

Installation

npm install derhuerst/pan-european-public-transport

pan-european-public-transport expects a Redis server running on localhost:6379. You can configure a different hostname/port via the REDIS_URL environment variable.

Usage

The API mimicks the hafas-client@5 API.

const client = require('pan-european-public-transport')

const inBerlin = {
	type: 'location',
	address: 'Großer Bunkerberg in Volkspark Friedrichshain',
	latitude: 52.526367, longitude: 13.432154
}
const inHamburg =  {
	type: 'location',
	address: 'Hansestadt Hamburg - Neustadt, Johannisbollwerk 6',
	latitude: 53.545056, longitude: 9.974467
}

const toHamburg = await client.journeys(inBerlin, inHamburg, {results: 1})
const [enrichedJourney] = toHamburg.journeys
console.log('enrichedJourney', enrichedJourney)

This will use the Deutsche Bahn endpoint for routing and enrich the journey using the VBB and HVV endpoints.

const wroclawGlowny = '5100069'

const [enrichedDeparture] = await client.departures('db', wroclawGlowny, {results: 1})
console.log('enrichedDeparture', enrichedDeparture)

This will fetch departures at Wrocław Główny using the Deutsche Bahn endpoint and enrich each departure using the PKP endpoint.

debugging

If you want to find out what it does, run with the following env var:

export DEBUG='pan-european-public-transport*,-pan-european-public-transport:hafas*,find-hafas-data-in-another-hafas*'

Related

Contributing

If you have a question or need support using pan-european-public-transport, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.