Expand network graphics from the Netzgrafik-Editor into timetables and export them in various formats, including GTFS and MATSim. | Read-only mirror of https://github.com/SchweizerischeBundesbahnen/netzgrafik-editor-converter — SBB. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
github-actions[bot] 956bcecad8
chore(main): release 5.0.0 (#238)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-12-01 16:37:50 +01:00
.github ci: merge minor and patch updates of Dependabot automatically (#237) 2026-11-14 00:13:01 +01:00
.idea build(deps)!: require Java 25 and update dependencies (#217) 2026-10-12 16:29:27 +02:00
.mvn/wrapper build(deps): bump org.apache.maven:apache-maven from 3.10.1 to 3.10.2 (#245) 2026-11-23 08:08:27 +00:00
app chore(main): release 5.0.0 (#238) 2026-12-01 16:37:50 +01:00
docs feat!: convert drawn connections into GTFS transfers (#239) 2026-11-30 01:18:50 +01:00
lib chore(main): release 5.0.0 (#238) 2026-12-01 16:37:50 +01:00
test chore(main): release 5.0.0 (#238) 2026-12-01 16:37:50 +01:00
.gitignore build(deps)!: require Java 25 and update dependencies (#217) 2026-10-12 16:29:27 +02:00
CHANGELOG.md chore(main): release 5.0.0 (#238) 2026-12-01 16:37:50 +01:00
CODING_STANDARDS.md chore: add coding standards document 2024-12-10 15:39:33 +01:00
CONTRIBUTING.md doc: add link to contributing guidelines in the readme 2024-12-10 16:18:21 +01:00
jitpack.yml build(deps)!: require Java 25 and update dependencies (#217) 2026-10-12 16:29:27 +02:00
LICENSE chore: change license to GPLv3 or later 2024-12-02 13:35:10 +01:00
lombok.config feat: support asymmetric trainruns (#220) 2026-10-13 13:13:01 +02:00
mvnw build(deps)!: require Java 25 and update dependencies (#217) 2026-10-12 16:29:27 +02:00
mvnw.cmd build(deps)!: require Java 25 and update dependencies (#217) 2026-10-12 16:29:27 +02:00
pom.xml chore(main): release 5.0.0 (#238) 2026-12-01 16:37:50 +01:00
README.md fix(converter): preserve disconnected trainrun sections (#242) 2026-11-30 10:49:01 +01:00
RELEASE.md build(ci): setup release please 2024-12-10 17:40:43 +01:00

Netzgrafik-Editor Converter

Converter to expand network graphics from the Netzgrafik-Editor into timetables for the entire service day in different formats, as for example GTFS static or MATSim transit schedules.

Usage

Command line

Run the command line tool to convert a network graphic to either a GTFS or MATSim timetable:

Usage: convert [-htV] [--non-passenger-network] [-b=<serviceDayBoundary>]
               [-d=<depotLabel>] [-e=<serviceDayEnd>] [-f=<outputFormat>]
               [-i=<stopFacilityCsv>] [-r=<rollingStockCsv>]
               [-s=<serviceDayStart>] [-v=<validationStrategy>]
               [--non-passenger-categories=<nonPassengerCategories>[,
               <nonPassengerCategories>...]]... <networkGraphicFile>
               <outputDirectory>

Converts network graphics into timetables in various formats.
      <networkGraphicFile>   The network graphic file to convert.
      <outputDirectory>      The output directory for the converted timetable.
  -b, --service-day-boundary=<serviceDayBoundary>
                             Handling of trips at the service day boundaries
                               (FULL, CLIP, DEPOT).
  -d, --depot-label=<depotLabel>
                             Node label which marks the depots in the network
                               graphic.
  -e, --service-day-end=<serviceDayEnd>
                             Service day end time (HH:mm).
  -f, --format=<outputFormat>
                             Output format (GTFS or MATSim).
  -h, --help                 Show this help message and exit.
  -i, --stop-facility-csv=<stopFacilityCsv>
                             File which contains the coordinates of the stop
                               facilities.
      --non-passenger-categories=<nonPassengerCategories>[,
        <nonPassengerCategories>...]
                             Trainrun categories without passenger service, as
                               comma-separated short names (e.g. G,GEX). Their
                               trains run, but cannot be boarded.
      --non-passenger-network
                             Convert only the trainruns without passenger
                               service, as a network of their own in which they
                               can be boarded and left at every node they run
                               through, with transfers only at the drawn
                               connections (GTFS only).
  -r, --rolling-stock-csv=<rollingStockCsv>
                             File which contains the vehicle types to be mapped
                               to network graphic categories.
  -s, --service-day-start=<serviceDayStart>
                             Service day start time (HH:mm).
  -t, --train-names          Use train names as route or line IDs (true/false).
  -v, --validation=<validationStrategy>
                             Validation strategy (SKIP_VALIDATION,
                               WARN_ON_ISSUES, FAIL_ON_ISSUES,
                               REPLACE_WHITESPACE, REMOVE_SPECIAL_CHARACTERS).
  -V, --version              Print version information and exit.

Since the Netzgrafik-Editor does not provide information about the coordinates of nodes or rolling stock (vehicle types) serving a category, this information can optionally be provided through CSV files.

Example:

# configure paths
NETWORK_GRAPHIC_FILE=../test/src/main/resources/ng/scenarios/realistic.json
OUTPUT_DIRECTORY=../integration-test/output/cmd

# output format: GTFS or MATSIM 
OUTPUT_FORMAT=GTFS

# optional CSV repositories
STOP_FACILITY_INFO_FILE=../test/src/main/resources/ng/scenarios/realistic-stop-facility-info.csv
ROLLING_STOCK_INFO_FILE=../test/src/main/resources/ng/scenarios/realistic-rolling-stock-info.csv

# run the Spring command line runner app to convert to GTFS / MATSim format
ARGS="$NETWORK_GRAPHIC_FILE $OUTPUT_DIRECTORY -f $OUTPUT_FORMAT -i $STOP_FACILITY_INFO_FILE -r $ROLLING_STOCK_INFO_FILE"
./mvnw spring-boot:run -pl app -Dspring-boot.run.arguments=$ARGS

Service day boundary

The trainruns repeat with their frequency from their times in the Netzgrafik-Editor, independent of the service day start. The service day boundary defines how trips at the start and end of the service day are handled:

Boundary Trips
FULL (default) Run their full route if they depart from their first stop within the service day.
CLIP Are clipped to the stops served within the service day.
DEPOT Like CLIP, but start and end at depots only.

Depots are the nodes labelled Depot in the Netzgrafik-Editor (--depot-label) where a line stops; line termini always count as depots. See Service Day Boundary for the exact rules, the handling of lines without depot by the validation strategy, and time-distance diagrams.

Trainruns with a gap

The Netzgrafik-Editor keeps the parts of a trainrun after a section in its middle was deleted, e.g. for a partial cancellation. The converter writes each connected part as a line of its own, named after its first and last node, with the times drawn for it.

Connections

The connection time of a node becomes the minimum transfer time of its stop (GTFS transfer_type 2, MATSim minimal transfer time). The connections drawn in the nodes of the Netzgrafik-Editor become GTFS transfers between the trips they link: a timed transfer (transfer_type 1) from the arriving to the departing trip, which waits for it. With different frequencies, only the trips that meet as drawn are connected. MATSim relates transfers to stop facilities only, so the connections are left out there.

Trainruns without passenger service, such as freight trains, empty runs, or construction, rescue and shunting trains, are marked by their category (--non-passenger-categories, e.g. G,GEX). Their trains run, but nobody boards them. With --non-passenger-network, the converter writes these trainruns alone and lets them be boarded and left at every node they run through, as a GTFS network in which a train changes to another trainrun only at a drawn connection, in no time. See Connections for the rules, the handling of connections that cannot be converted as drawn by the validation strategy, and an example.

Converter in Java

In most cases, the repositories for infrastructure, rolling stock, and vehicle circuits used by the supply builder will be custom. To configure the converter with these custom repositories, inject them into the supply builder of the selected timetable output format (refer to the Design section for details) and run the conversion:


public class Example {

    public static final Path NETWORK_GRAPHIC_FILE = Path.of("path/to/networkGraphic.json");
    public static final Path OUTPUT_DIRECTORY = Path.of("path/to/outputDirectory");
    public static final NetworkGraphicConverterConfig CONFIG = NetworkGraphicConverterConfig.builder().build();

    static void main(String[] args) throws IOException {

        // define network graphic source
        NetworkGraphicSource source = new JsonFileReader(NETWORK_GRAPHIC_FILE);

        // instantiate custom implementations of the repositories
        RollingStockRepository customRollingStockRepository = new CustomRollingStockRepository();
        InfrastructureRepository customInfrastructureRepository = new CustomInfrastructureRepository();
        VehicleCircuitsPlanner customVehicleCircuitsPlanner = new CustomVehicleCircuitsPlanner(
                customRollingStockRepository);

        // convert to GTFS
        setupGtfsConverter(customInfrastructureRepository, customRollingStockRepository, customVehicleCircuitsPlanner,
                source).run();

        // convert to MATSim
        setupMatsimConverter(customInfrastructureRepository, customRollingStockRepository, customVehicleCircuitsPlanner,
                source).run();
    }

    private static NetworkGraphicConverter<Scenario> setupMatsimConverter(
            InfrastructureRepository customInfrastructureRepository, RollingStockRepository customRollingStockRepository,
            VehicleCircuitsPlanner customVehicleCircuitsPlanner, NetworkGraphicSource source) {
        SupplyBuilder<Scenario> builder = new MatsimSupplyBuilder(customInfrastructureRepository,
                customRollingStockRepository, customVehicleCircuitsPlanner, CONFIG.getValidationStrategy());
        ConverterSink<Scenario> sink = new TransitScheduleXmlWriter(Example.OUTPUT_DIRECTORY, "");

        return new NetworkGraphicConverter<>(CONFIG, source, builder, sink);
    }

    private static NetworkGraphicConverter<GtfsSchedule> setupGtfsConverter(
            InfrastructureRepository customInfrastructureRepository, RollingStockRepository customRollingStockRepository,
            VehicleCircuitsPlanner customVehicleCircuitsPlanner, NetworkGraphicSource source) {
        SupplyBuilder<GtfsSchedule> builder = new GtfsSupplyBuilder(customInfrastructureRepository,
                customRollingStockRepository, customVehicleCircuitsPlanner);
        ConverterSink<GtfsSchedule> sink = new GtfsScheduleWriter(Example.OUTPUT_DIRECTORY, true);

        return new NetworkGraphicConverter<>(CONFIG, source, builder, sink);
    }

}

Design

The Maven project is structured into three modules: app, lib and test.

Application

A command-line application based on Spring Boot's CommandLineRunner, which serves as the entry point for interacting with the converter. The application module isolates the Spring Boot dependency.

Library

The core functionality of the project is encapsulated in the library module, which provides the logic for reading, converting, and writing network graphic data. The library has a modular design (DI):

  • converter: Reads a network graphic from a source, converts it, and writes to a sink.
    • core: Converter logic and configuration.
      • model: DTOs to read network graphic data from JSON.
      • supply: A generic supply builder interface. Defines infrastructure and rolling stock repositories, as well as vehicle circuits planner interfaces used in the builder.
      • validation: Network graphic ID validator and sanitizer.
    • adapter: Format-specific transit schedule builder, implementing the supply builder interface.
    • io: Provides implementations for network graphic sources and converter output sinks.
    • utils: Utilities used across multiple domains.

The class diagram outlines core classes and their relationships:

Class diagram

Testing

Enables access to test case files and provides a JUnit Jupiter Extension for easy integration test directory path handling. Both the library and application modules depend on this module in the test scope.

Contributing

This repository includes Contribution Guidelines that outline how to contribute to the project, including how to submit bug reports, feature requests, and pull requests. The Coding Standards outline best practices and rules to follow when coding. Details on releasing are described in the Release document.

License

This project is licensed under GNU GPL-3.0.

© 2024 Swiss Federal Railways SBB AG.