A web application made with React that allows checking real-time train schedules, locations, and compositions of trains in Finland. The app uses data from open APIs provided by Fintraffic / Digitraffic and Helsinki regional traffic / Digitransit, licensed by CC BY 4.0.
Live version running at junaan.fi.
See the instructions below for development.
You need the following tools:
- Node.js
>= 18
- npm
>= 10
Register to the Digitransit API Portal and create yourself a new API subscription key.
Copy the example configuration values from the .env
file to a new file named
.env.local
and replace the values with your own.
npm run dev
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
npm run gql-codegen
Run the above command whenever you modify the GraphQL queries in the
src/graphql/queries
folder or when the remote GraphQL schema is modified.
Note that the above command is also run as part of the prestart
script when
running npm start
.
npm test
Launches the test runner in the interactive watch mode.
npm run build
Builds the app for production to the out
folder.
Extract the map tile files (.pbf) from MBTiles in data
and output the files
to public/tiles
using npm run extract-tiles-public
.
-
Download the railway network map layer data from Finnish Transport Infrastructure Agency's Download- and viewing service
- Choose Map layers -> Rail traffic -> Finnish rail network -> Railway network (multi-track).
-
Unzip the downloaded archive and convert the shape to GeoJSON using ogr2ogr.
ogr2ogr -f GeoJSON ./data/railway_tracks.geojson locationtracks_simplifiedLine.shp -s_srs EPSG:3 067 -t_srs EPSG:4326
-
Generate MBTiles using tippecanoe by Mapbox.
tippecanoe -o ./data/railway_tracks.mbtiles --drop-densest-as-needed ./data/railway_tracks.geojson --no-tile-compression --maximum-zoom=14
-
Fetch the OpenStreetMap (OSM) railway platform GeoJSON data through Overpass API for each station. See steps to do this below (CLI tool to be released later).
-
Perform the following query for each station:
[out:json]; nwr(around:1000,<station lat>,<station lon>)[railway=platform]; out geom;
-
Convert the response OSM data to GeoJSON using osmtogeojson.
-
Merge the features from all platforms into single feature collection and save the file to
data/railway_platforms.json
.
-
-
Generate MBTiles using tippecanoe by Mapbox.
tippecanoe -o ./data/railway_platforms.mbtiles --drop-densest-as-needed ./data/railway_platforms.json --no-tile-compression --minimum-zoom=14 --maximum-zoom=18
npm run generate-station-line-km-location-data
Fetches the line kilometer (ratakilometri) location data for all train stations in
Finland from Digitraffic Infra API
and outputs it to src/utils/generated/line-km-location-by-station-code.json
.
This data is used to determine train direction
at each station based on the increasing or decreasing line kilometers.
npm run generate-station-platform-data
Fetches the station platform (laituri) data for all train stations in Finland
from Finnish Transport Infrastructure Agency's Open API
and outputs it to src/utils/generated/station-platform-by-station-platform-id.json
.
This data is used to determine which side the station platform is (left or
right) according to the train direction.
See getStationPlatformSide.ts for the logic.
Copyright (C) 2024 Vili Ketonen