iRail / stations

A list of all the Belgian stations and their properties used within the iRail project
http://irail.be/stations/NMBS
30 stars 20 forks source link
belgium json-ld sncb stations

All stations in Belgium

Build Status Dependency Status Software License

We try to maintain a list of all the stations in Belgium using CSV so everyone can help to maintain it on github. Furthermore, we have a PHP composer/packagist library for you to go from station name to ID and vice versa and we convert the CSV file to JSON-LD for maximum semantic interoperability.

Fields we collect

stations.csv

This file describes all NMBS/SNCB stations in Belgium. A station can have multiple platforms (stops), which are described in stops.csv.

stops.csv

This file describes all NMBS/SNCB stops in Belgium. Each platform is a separate stop location. All fields are computed using gtfs_data_extractor.php.

facilities.csv

This file describes facilities available in NMBS/SNCB stations. All fields are computed using web_facilities_extractor.php.

embarkment_statistics.csv

This file describes how many people embark a train at the given station per day. Statistics from october 2023, source: belgiantrain.be, Cijfers opgestapte reizigers

How we collect data

This repository contains two PHP scripts which can load all data from the NMBS GTFS public data and the NMBS website. These scripts can be used to generate all CSV files from scratch, and to update existing files.

Manual changes and corrections can be made to stations.csv. It is recommended to use the stations.csv file in this repository as a starting point instead of using the scripts to generate this file, as the repository versions includes manual fixes to station names and translations.

Any changes made to stops.csv or facilities.csv will be overwritten by the scripts. Therefore, any pull requests with the sole purpose of updating/modifying these files won't be accepted

Missing stations and missing fields in stations.csv are automatically added when the gtfs_data_extractor tool runs.

How to make a correction

Corrections to names, translations and locations can be made by adjusting fields in stations.csv:

If you want to make a correction to facilities.csv or stops.csv, don't fix the files, but fix the scripts instead, and let these scripts run to update the file for you.

In case you just want to reuse the data

Latest update over HTTP

JSON-LD is available at https://irail.be/stations/NMBS if you add the right accept header. For example, using curl on the command line, you would do this:

curl -H "accept: application/json" https://irail.be/stations/NMBS

If you want to change this output, please change the CSV files over here first (we love pull requests)

In PHP project

Using composer (mind that we also require nodejs to be installed on your system in order to use the linked-data interface):

composer require irail/stations

Then you can use the stations in your code as follows:

use irail\stations\Stations;
use irail\stations\StationsLd;
// Using the strongly typed CSV parser:
// getStations() returns a irail\stations\Station array
$brusselsnorth = Stations::getStations("Brussels North")[0];
// getStationByID($id) returns a irail\stations\Station object with the station or null
$ghentstpieters = Stations::getStationByID("http://irail.be/stations/NMBS/008892007");

// Using the linked-data interface
// getStations() returns a json-ld document
$brusselsnorth = StationsLd::getStations("Brussels North")->{"@graph"}[0];
// getStationByID($id) returns a simple object with the station or null
$ghentstpieters = StationsLd::getStationByID("http://irail.be/stations/NMBS/008892007");

Don't forget to do a composer update from time to time to update the data

Building the RDF or JSON-LD

Using scripts, this data can be converted to JSON-LD. In order to run the script, run this command:

First time run this in your terminal (nodejs needs to be installed on your system):

npm install

Or install it globally using the npm package (you will need to run this again when there's an update to the stations file):

npm install -g irail-stations

From then on, you can always run:

# using this repo
./bin/build.js
# or with the global package:
irail-stations

For extra commands, check:

./bin/build.js --help
# or
irail-stations --help

We currently support the output formats TRiG, N-Quads and JSON-LD (default)

License

CC0: This dataset belongs to the public domain. You're free to reuse it without any restrictions whatsoever.

If you contribute to this repository, you agree that your contributions will be licensed under the CC0 open data license.

We do appreciate a link back to this repository, or a mention of the iRail project.