Trips

SNCB: belgium's national train operator

Format
MF-JSON
Updates
On request — aggregated from vehicle-position over the queried interval
curl -H "Authorization: Bearer $MOBILITYTWIN_TOKEN" "https://api.mobilitytwin.brussels/sncb/trips"
Get a token

All the trips of SNCB for the specified period of time. This is an aggregate of the GeoJSON files returned by the vehicle-position endpoint of MobilityTwin.Brussels.

OGC Moving Features JSON: one trajectory per trip.

Parameters

NameMeaning
start_timestampStart of the range, in Unix seconds or ISO 8601. Without any timestamp, the last hour is used; with only one, the hour starting or ending at it.
end_timestampEnd of the range, in Unix seconds or ISO 8601.

Response fields

FieldTypeMeaning
trip_idstringUnique identifier of the trip.
trip_headsignstringDestination displayed on the train.
name_startstringName of the departure station.
name_endstringName of the arrival station.
ptcarid_startstringInfrabel PTCAR id of the first station.
ptcarid_endstringInfrabel PTCAR id of the last station.
features[].temporalGeometry.typestring
features[].temporalGeometry.coordinatesarrayArray of [longitude, latitude] positions.
features[].temporalGeometry.datetimesarrayISO 8601 timestamps corresponding to each coordinate.
features[].temporalGeometry.interpolationstringInterpolation method between points.

Python example

import requests
import movingpandas as mpd

from datetime import datetime, timedelta, timezone

end = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0)
start = end - timedelta(hours=1)
params = {
    "start_timestamp": start.isoformat(),      # ISO accepted; epoch also works
    "end_timestamp": end.isoformat(),
}

url = "https://api.mobilitytwin.brussels/sncb/trips"

data = requests.get(url, headers={
        'Authorization': 'Bearer [MY_API_KEY]'
}, params=params).json()

# Load as a MovingPandas TrajectoryCollection
tc = mpd.io.read_mf_dict(data, traj_id_property="trip_id")

# Print summary of each trajectory
for traj in tc.trajectories:
    print(f"Trip {traj.id}: {traj.get_length():.0f}m, duration: {traj.get_duration()}")

# Plot all train trajectories on a map
tc.plot(figsize=(12, 8), linewidth=1)