Skip to main content
Rail transport operations model cargo moved by train between rail yards. Set the transport operation type to RAIL within a transport chain when a shipment leg is moved by rail. TerraTwin can calculate rail emissions from a very small amount of information, but rail transport is sensitive to the train consist, the selected rail yards, the rail route, and whether each section of the route is operated using electric or diesel traction.

Mode

Use type: "RAIL" in a transportChain transport element.TerraTwin treats that element as a requested rail leg between the surrounding transport chain locations.

Train

Use vehicle when you know the train consist.If the exact consist is unknown, use trainType, grossTrainWeight, and cargo.category to guide train selection.

Rail yards

If the leg does not start or end at a RAIL_YARD, TerraTwin selects suitable rail yards automatically.The rail movement is routed between those rail yards.

Connectors

If the origin or destination is not already a rail yard, TerraTwin can automatically add first mile and last mile road transport.Use firstMile and lastMile when the road vehicle configuration is known.
Use RAIL when cargo is modeled as freight moving by train. A road journey that uses a roll-on/roll-off train service, such as the Channel Tunnel shuttle, is normally modeled as ROAD. When the selected road route uses the rail crossing, TerraTwin represents it as a sub-operation of the ROAD transport operation.

Basic shape

A minimal rail operation only needs type: "RAIL" in the transport chain:

CF10 1EP Cardiff to 8000 Bruges

In this request, the transport mode is specified by the type property on the transport operation. Because the origin and destination are places rather than rail yards, TerraTwin selects suitable rail yards and adds road connector movements where needed.
When TerraTwin adds first-mile or last-mile road transport, automatic hub insertion can also add HUB operations at the road-to-rail and rail-to-road transfers. See the logistics hubs guide for how these hubs are selected and how to control them with options.hubInsertion.
The more information you can provide about the train, the more accurately TerraTwin can model the transport operation. The most specific option is to provide the exact train vehicle and energyType:

Fukuoka to Tokyo

This asks TerraTwin to model the cargo as being transported by an electric, double-stack container freight train. Because both endpoints are rail yards, no first-mile or last-mile road connectors are needed.

Properties


Selecting rail as the mode

The mode is selected with the type property on a transport operation:
The rail operation runs between the nearest chain boundaries. Those boundaries come from the top-level origin and destination, or from surrounding HUB elements in a larger transportChain.

Anchorage to St. John's via Vancouver and Quebec

In this example, the HUB elements explicitly separate the sea and rail legs.
These intermediate hubs omit hubType. With automatic hub insertion enabled, TerraTwin selects their hub types from the surrounding WATER to RAIL and RAIL to WATER transitions. With options.hubInsertion: "MANUAL", they remain location boundaries but do not add hub emissions. See the How a hub type is selected for hub type selection and insertion rules.

Train selection

Rail supports two broad train consist families:

Manifest trains

Use trainType: "MANIFEST" for general mixed cargo services using multiple wagon types.Emissions are calculated from the train size, which can be selected using grossTrainWeight.

Unit trains

Use trainType: "UNIT" for dedicated services carrying one cargo type.Emissions are calculated from the cargo specific train configuration selected from cargo.category.
There are several ways to influence train selection. You do not need to provide all of them. In general, the more information you can provide about the train, the more accurately TerraTwin can model the transport operation. TerraTwin applies train selection in this order:

Direct train selection with vehicle

Use vehicle when you know the train consist. Supported train values include both manifest train sizes and unit train types:

Building materials, such as cement, from San Juan to the Port of Buenos Aires

When vehicle is set, TerraTwin uses that vehicle class for train selection. Any trainType, grossTrainWeight, or cargo.category values are not used to choose the train.
cargo.category may still affect other parts of the calculation. For example, it can influence cargo density, climate-control defaults, connector road vehicle selection, and hub defaults. It is only ignored for the purpose of selecting the train when vehicle is provided.

Manifest trains and grossTrainWeight

Use trainType: "MANIFEST" when the cargo moves on a general mixed cargo freight train. For manifest trains, grossTrainWeight is used to choose the train size.

Mixed cargo from the Port of Fujairah [AEFJR] to Al Ghuwaifat Station

The gross weight is mapped to a manifest train class: grossTrainWeight supports these units:
If trainType is MANIFEST and grossTrainWeight is omitted, TerraTwin chooses a default manifest train size based on the region of operation. For example, AVERAGE_TRAIN is the European default and HEAVY_TRAIN is the USA and Canada default.

Unit trains and cargo category mappings

Use trainType: "UNIT" when the cargo moves on a dedicated freight train carrying one cargo type. For unit trains, grossTrainWeight is ignored and cargo.category is used to select the train configuration.

Iron ore from the Port of Antwerp [BEANR] to the ArcelorMittal Eisenhüttenstadt steelworks

The automatic unit train selection follows the cargo category: For containerized categories such as GENERAL and REFRIGERATED_BULK, TerraTwin applies country specific defaults when selecting the container train configuration. European container rail is modelled as single-stacked, while countries where double-stacking is typical, such as the USA and India, default to double-stacked container trains.
If cargo.category is omitted, it defaults to GENERAL. With trainType: "UNIT", that means TerraTwin will usually treat the cargo as containerized unless you provide a more specific category.

Energy type and electrification

energyType influences rail emissions because electric and diesel traction use different emissions factors. Rail supports two values: The default is ELECTRICITY, but this does not mean the whole route is forced to be electric. Electricity is only used where the rail line supports electric traction. Where the route uses non-electrified rail infrastructure, TerraTwin models diesel traction for that part of the route.

Southampton to Cardiff, switching from diesel (orange) to electric (green) on the Filton Chord

For electric rail sections, emissions are calculated country by country as the train passes through each national grid. When a rail route crosses a country border, TerraTwin switches the electricity emissions factor at that border. A route from Belgium through Germany into Poland, for example, can use Belgian grid factors, then German grid factors, then Polish grid factors for the electric portions in each country.

Dates and time zones

departureDateTime and arrivalDateTime are optional, but provide them when they are known. They make emissions certificates and analytics more useful by linking results to the period in which the transport occurred.
Local date-times are interpreted using the time zone of the relevant rail yard:
  • departureDateTime is resolved using the start location’s time zone.
  • arrivalDateTime is resolved using the end location’s time zone.
Dates can be supplied in several formats: UTC
Local time
Interpreted using the start location’s time zone for departureDateTime, or the end location’s time zone for arrivalDateTime. Explicit offset
Date only

Route polylines

By default, calculation results do not include the geometry of the calculated rail route. Set the top-level options.includeRoutePolylines property to true when you need route geometry for mapping, visualization, or downstream spatial processing:
When enabled, the RAIL result includes a route property containing the full train route encoded using the Google Encoded Polyline Algorithm Format. The rail polyline represents the train movement between the selected rail yards. If TerraTwin adds first-mile or last-mile road transport, those connector movements are returned as separate ROAD results. Because includeRoutePolylines is a top-level option, their corresponding route properties are also included.
includeRoutePolylines defaults to false. When it is omitted or set to false, route properties are not included in the response.

Routing failure and mode fallback

Rail routing can fail when TerraTwin cannot build a feasible rail operation for the requested leg. This can happen when no rail yard can be reached from the start or end location, or when no connecting rail route can be found between the selected rail yards. Use options.fallbackTransportModes to let TerraTwin switch to another transport mode when the requested rail operation cannot be realized. Fallback modes are tried in the order you provide, excluding the mode that failed.

Reykjavik to Oslo failover to ROAD (and RoRo ferry) transport

In this request, TerraTwin first attempts to calculate the leg as rail transport. This fails because there are no railways on Iceland, so no rail route can be generated from Reykjavik. TerraTwin then tries the fallback modes in order: ROAD, WATER, then AIR. The ROAD fallback succeeds because the route can be calculated as a road journey with RoRo ferry connections from Seyðisfjörður to Kristiansand. Since ROAD is the first fallback mode that can be routed and calculated, that result is returned. If firstMile or lastMile settings are configured on the rail leg, TerraTwin applies them to fallback modes where they are relevant. If every fallback attempt fails, the API returns the error from the final fallback mode attempted.
If a rail operation fails and TerraTwin uses a fallback mode instead, any id or context provided on the failed rail operation is preserved and returned with the replacement operation’s result.

Recommendations

1

Set the rail mode explicitly

Use type: "RAIL" in the transport operation when the leg is known to move by train.
2

Provide the vehicle when the train is known

Set vehicle to the exact supported train class when the train consist is known. This avoids automatic selection and gives the most direct calculation input.
3

Use trainType for the operating pattern

Use MANIFEST for mixed cargo services and UNIT for dedicated commodity trains.
4

Add grossTrainWeight for manifest trains

For MANIFEST trains, provide gross train weight when known so TerraTwin can select the correct train size.
5

Set the cargo category for unit trains

For UNIT trains, provide cargo.category so TerraTwin can select the correct dedicated train type. Do not rely on the default GENERAL category unless the cargo should be treated as containerized general freight.
6

Review energy assumptions

The default is electric traction where supported, with diesel used on non-electrified rail sections. Set energyType: "DIESEL" when the service is known to be diesel hauled.
7

Configure first and last mile when known

Use firstMile and lastMile when the origin or destination is not a rail yard and you know the road vehicle details. Otherwise, let TerraTwin choose appropriate road defaults.
8

Include route geometry when needed

Set options.includeRoutePolylines to true when you need the calculated train route in the response. If the journey includes first-mile or last-mile road connectors, use the separate route value from each returned transport result to reconstruct the complete journey.
9

Use fallback modes for uncertain routability

Add options.fallbackTransportModes when a requested rail route may not be feasible and another mode should be attempted automatically.