Trips
SNCB: belgium's national train operator
- Format
- MF-JSON
- Updates
- On request — aggregated from
vehicle-positionover the queried interval
curl -H "Authorization: Bearer $MOBILITYTWIN_TOKEN" "https://api.mobilitytwin.brussels/sncb/trips"
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
| Name | Meaning |
|---|---|
start_timestamp | Start 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_timestamp | End of the range, in Unix seconds or ISO 8601. |
Response fields
| Field | Type | Meaning |
|---|---|---|
trip_id | string | Unique identifier of the trip. |
trip_headsign | string | Destination displayed on the train. |
name_start | string | Name of the departure station. |
name_end | string | Name of the arrival station. |
ptcarid_start | string | Infrabel PTCAR id of the first station. |
ptcarid_end | string | Infrabel PTCAR id of the last station. |
features[].temporalGeometry.type | string | |
features[].temporalGeometry.coordinates | array | Array of [longitude, latitude] positions. |
features[].temporalGeometry.datetimes | array | ISO 8601 timestamps corresponding to each coordinate. |
features[].temporalGeometry.interpolation | string | Interpolation 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)