Skip to content

viliket/live-trains-finland

Repository files navigation

Junaan.fi

Test workflow codecov Codacy Badge GitHub top language Website

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.

Development

See the instructions below for development.

Prerequisites

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.

Run the app

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.

Regenerate GraphQL operations

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.

Run the tests

npm test

Launches the test runner in the interactive watch mode.

Create production build

npm run build

Builds the app for production to the out folder.

Regenerate the map tiles

Extract the map tile files (.pbf) from MBTiles in data and output the files to public/tiles using npm run extract-tiles-public.

Generate MBTiles for railway_tracks

  1. 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).
  2. 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
  3. 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

Generate MBTiles for railway_platforms

  1. 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.

  2. 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

Regenerate train station line km location data

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.

Regenerate train station platform data

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.

License

Copyright (C) 2024 Vili Ketonen

GNU General Public License version 3 (GPLv3)

About

๐Ÿš† Real-time train schedules, locations, and compositions in Finland.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published