Skip to content

GTFS Schedule

The GTFS Schedule module provides an implementation of the General Transit Feed Specification (GTFS) Schedule for Kotlin Multiplatform.

GTFS Schedule is a standardized data format for public transit schedules and associated geographic information. It consists of a ZIP archive containing CSV files that describe transit routes, stops, trips, and schedules.

Features

  • CSV encoding and decoding with kotlin-dsv
  • Strong type safety, with appropriate standard library or kotlinx-datetime types
  • Kotlin Multiplatform support (JVM, Native, JS, WASM)

Status

This module is currently in progress and provides a partial implementation of the GTFS Schedule specification. The following files are supported:

  • agency.txt
  • routes.txt
  • trips.txt
  • stops.txt
  • stop_times.txt
  • calendar.txt
  • calendar_dates.txt

See issue #8 for the current roadmap and implementation status.

Installation

Add the dependency to your build.gradle.kts:

dependencies {
    implementation("dev.sargunv.mobility-data:gtfs-schedule:0.4.0")
}

Example

SystemFileSystem.source(Path("path/to/gtfs/agency.txt")).buffered().use { source -> // (1)!
  val agencies = GtfsCsv.decodeFromSource<Agency>(source) // (2)!
  agencies.forEach { agency -> // (3)!
    println("Agency: ${agency.agencyName} (${agency.agencyId})")
  }
}
  1. Open a GTFS CSV file (typically extracted from a ZIP archive).
  2. Use the GtfsCsv format which is preconfigured for GTFS .txt files.
  3. Decode the CSV file into a sequence of strongly-typed entities and process them as needed.

API Reference

For detailed API documentation, see the API Reference.