ratakilometri
v3.0.2
Published
With Yarn:
Downloads
15
Readme
Find the shortest route between two railway stations of Finland by using Dijkstra's algorithm. Station location data the library is using, is extracted from the PDF provided by Finnish Transport Agency and enriched with other information available freely on the Internet.
Install
With Yarn:
yarn add ratakilometri
Or with NPM:
npm i -S ratakilometri
Usage
const { getRoute, getDistance } = require('ratakilometri')()
Or this way:
import ratakm from 'ratakilometri'
const { getRoute, getDistance } = ratakm()
To find out distance or route:
const route = getRoute('HL', 'KV')
const distance = getDistance('TUS', 'HKI')
console.log(route, distance)
Options
As we pass parameters of getRoute
almost directly to node-dijkstra
, you can use options object of the library as a third parameter of getRoute
.
trim: boolean
, defaultfalse
: If set to true, the result won't include the start and end stations.reverse: boolean
, defaultfalse
: If set to true, the route array will be in reversed order, from the end to startavoid: array
, default[]
: Stations to be avoided
:information_source: Be aware algorithm really tries to find out the shortest path which isn't always the best path. For example, if you try to find out distance from Leppävaara (LPV) to Tikkurila (TKL) for the commercial passenger train, library would tell you to go thru Ilmala Rail Yard (ILR) which surely isn't the best route :wink: