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.
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:
- 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.
- 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.
- 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.
- 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
- fetch results (called journeys) from an endpoint that covers both A and B
- identify other endpoints that may have additional data about the parts of the journey (called legs), using
- their coverage/service area
- a list of rules which data to use each endpoint for
- 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
- fetch results from the "most local" endpoint that covers A
- identify other endpoints that may have additional data
- 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:
- unlike Linked Connections, it does not do routing across federated data (yet?),
- design-wise, it relies smart/powerful servers (instead of the "smart clients, simple servers" design),
- it is not based on open standards and open data.
Nevertheless, it
- pulls results from multiple data sources and merges them,
- uses a subset of endpoints that can give meaningful results for each query,
- allows to gradually swap out a closed & proprietary endpoint with e.g. GTFS + Navitia, or even a Linked Connections router.
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
- Why linked open transit data?
- Linked Connections
find-hafas-data-in-another-hafas
– Find data from one HAFAS endpoint in another one.stable-public-transport-ids
– Get stable IDs for public transport stations, etc.vbb-hafas
– JavaScript client for the VBB HAFAS API.db-hafas
– JavaScript client for the DB HAFAS API.insa-hafas
– JavaScript client for the NASA/INSA HAFAS API.
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.