Load GTFS files in golang

Overview

go-gtfs

Load GTFS files in Go.

godoc for artonge/go-gtfs

Go goreportcard for artonge/go-gtfs

PRs Welcome

The project is in maintenance mode.

It is kept compatible with changes in the Go ecosystem but no new features will be developed. PR could be accepted.

Install

go get github.com/artonge/go-gtfs

Examples

Load one directory containing GTFS files:

path/to/gtfs_files
├── agency.txt
├── calendar_dates.txt
├── calendar.txt
├── routes.txt
├── stops.txt
├── stop_times.txt
├── transfers.txt
└── trips.txt
g, err := gtfs.Load("path/to/gtfs_files", nil)

Load a directory containing sub directories containing GTFS files:

path/to/gtfs_directories
├── gtfs1
│   ├── agency.txt
│   ├── calendar_dates.txt
│   ├── routes.txt
│   ├── stops.txt
│   ├── stop_times.txt
│   ├── transfers.txt
│   └── trips.txt
└── gtfs2
    ├── agency.txt
    ├── calendar_dates.txt
    ├── calendar.txt
    ├── routes.txt
    ├── stops.txt
    ├── stop_times.txt
    ├── transfers.txt
    └── trips.txt
gs, err := gtfs.LoadSplitted("path/to/gtfs_directories", nil)

You can then access the data through the GTFS structure. That structure contains arrays of approriate structures for each files.

type GTFS struct {
	Path       string // The path to the containing directory
	Agency     Agency
	Routes     []Route
	Stops      []Stop
	StopsTimes []Stop
	Trips      []Trip
	Calendars  []Calendar
	Transfers  []Transfer
}

type Route struct {
	ID        string `csv:"route_id"`
	AgencyID  string `csv:"agency_id"`
	ShortName string `csv:"route_short_name"`
	LongName  string `csv:"route_long_name"`
	Type      int    `csv:"route_type"`
	Desc      string `csv:"route_url"`
	URL       string `csv:"route_desc"`
	Color     string `csv:"route_color"`
	TextColor string `csv:"route_text_color"`
}

...

Contributions

Pull requests are welcome ! :)

You might also like...
copy files for humans

Go-Decent-Copy go-decent-copy provides a copy file for humans Usage package main import "github.com/hugocarreira/go-decent-copy" func main() { e

An implementation of the FileSystem interface for tar files.

TarFS A wrapper around tar.Reader. Implements the FileSystem interface for tar files. Adds an Open method, that enables reading of file according to i

A Go io/fs filesystem implementation for reading files in a Github gists.

GistFS GistFS is an io/fs implementation that enables to read files stored in a given Gist. Requirements This module depends on io/fs which is only av

Create ePub files from URLs

url2epub Create ePub files from URLs Overview The root directory provides a Go library that creates ePub files out of URLs, with limitations.

🏵 Gee is tool of stdin to each files and stdout
🏵 Gee is tool of stdin to each files and stdout

Gee is tool of stdin to each files and stdout. It is similar to the tee command, but there are more functions for convenience. In addition, it was written as go. which provides output to stdout and files.

Format /etc/fstab files.
Format /etc/fstab files.

Format /etc/fstab files. Features and limitations Can format /etc/fstab files. Will use 2 spaces between all fields, if they are of equal length. The

Run a command when files change

Reflex Reflex is a small tool to watch a directory and rerun a command when certain files change. It's great for automatically running compile/lint/te

Easily create & extract archives, and compress & decompress files of various formats

archiver Introducing Archiver 3.1 - a cross-platform, multi-format archive utility and Go library. A powerful and flexible library meets an elegant CL

Embed files into a Go executable

statik statik allows you to embed a directory of static files into your Go binary to be later served from an http.FileSystem. Is this a crazy idea? No

Comments
  • Add function to dump gtfs to files

    Add function to dump gtfs to files

    This dumps a given gtfs-struct to a given path and accepts the same filters as Load() does.

    Unfortunately, due to the current implementation of go-csv-tag, Dump() can only accept slices, not pointers to slices; hence the pass by value.

    This is good enough for what I am using it for right now, but especially with bigger structures, passing the slices by reference would be nicer.

    If you'd like, I can take a look at changing the implementation of Dump to also accept pointers to slices; this would require the use of reflection, which I don't have much experience with so far.

    Thanks for your good work, Adrian

    opened by leftshift 4
  • Support for multiple agencies

    Support for multiple agencies

    Beware this is a breaking change as the GTFS model has been changed from using a single Agency to to Agencies []Agency.

    I've added another agency to the test feed, with a couple of empty routes.

    Fix #15

    opened by adrianmo 2
  • Support for multiple agencies

    Support for multiple agencies

    Currently the library only takes the first agency in the agency.txt, and that is OK for most feeds as they typically are single-agency feeds, however, other GTFS feeds contain data for more than one agency in the same feed. For example, the agency.txt file in the SNCF feed for Horaires des lignes Transilien looks like this:

    agency_id,agency_name,agency_url,agency_timezone,agency_lang
    DUA853,"Paris Nord",http://www.transilien.com,Europe/Paris,fr
    DUA854,"Paris St Lazare",http://www.transilien.com,Europe/Paris,fr
    DUA852,"Paris Rive Gauche",http://www.transilien.com,Europe/Paris,fr
    DUA803,"RER C",http://www.transilien.com,Europe/Paris,fr
    DUA804,"RER D",http://www.transilien.com,Europe/Paris,fr
    DUA850,"Paris Est",http://www.transilien.com,Europe/Paris,fr
    DUA855,"La Verrière - La Défense",http://www.transilien.com,Europe/Paris,fr
    DUA851,"Paris Sud Est",http://www.transilien.com,Europe/Paris,fr
    DUA805,"RER E",http://www.transilien.com,Europe/Paris,fr
    DUA802,"RER B",http://www.transilien.com,Europe/Paris,fr
    DUA801,"RER A",http://www.transilien.com,Europe/Paris,fr
    
    opened by adrianmo 2
Releases(v1.2.0)
  • v1.2.0(Sep 27, 2022)

    What's Changed

    • Support for multiple agencies by @adrianmo in https://github.com/artonge/go-gtfs/pull/16
    • Add project status to the README by @artonge in https://github.com/artonge/go-gtfs/pull/17
    • Add more supported file types by @csutorasa in https://github.com/artonge/go-gtfs/pull/18
    • Update go-csv-tag to v2.1.0 by @artonge

    New Contributors

    • @adrianmo made their first contribution in https://github.com/artonge/go-gtfs/pull/16
    • @csutorasa made their first contribution in https://github.com/artonge/go-gtfs/pull/18

    Full Changelog: https://github.com/artonge/go-gtfs/compare/v1.0.1...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(May 27, 2020)

Owner
Louis
Louis
Split text files into gzip files with x lines

hakgzsplit split lines of text into multiple gzip files

Luke Stephens (hakluke) 6 Jun 21, 2022
Easily create Go files from stub files

go-stubs Easily create .go files from stub files in your projects. Usage go get github.com/nwby/go-stubs Create a stub file: package stubs type {{.Mo

Sam Newby 4 Jan 27, 2022
app-services-go-linter plugin analyze source tree of Go files and validates the availability of i18n strings in *.toml files

app-services-go-linter app-services-go-linter plugin analyze source tree of Go files and validates the availability of i18n strings in *.toml files. A

Red Hat Developer 2 Nov 29, 2021
Golang wrapper for Exiftool : extract as much metadata as possible (EXIF, ...) from files (pictures, pdf, office documents, ...)

go-exiftool go-exiftool is a golang library that wraps ExifTool. ExifTool's purpose is to extract as much metadata as possible (EXIF, IPTC, XMP, GPS,

null 144 Nov 26, 2022
Golang PDF library for creating and processing PDF files (pure go)

UniPDF - PDF for Go UniDoc UniPDF is a PDF library for Go (golang) with capabilities for creating and reading, processing PDF files. The library is wr

UniDoc 1.7k Nov 28, 2022
Go (golang) library for reading and writing XLSX files.

XLSX Introduction xlsx is a library to simplify reading and writing the XML format used by recent version of Microsoft Excel in Go programs. Current s

Geoffrey J. Teale 5.4k Nov 25, 2022
Golang library for reading and writing Microsoft Excel™ (XLSX) files.

Excelize Introduction Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLSX / XLSM / XLT

360 Enterprise Security Group, Endpoint Security, inc. 13.5k Nov 28, 2022
Merge some files in a path with custom extension in golang

goMerge Merge some files in a path with custom extension in golang Feature Walk in a path with a goroutine using parallelism Merge files with custom e

Javad Rajabzade 4 Apr 26, 2022
Compute message digest for large files in Go

checksum test coverage Compute message digest, like MD5 and SHA256, in golang for potentially large files. Usage package main import ( "fmt" "githu

Jerry Zhao 74 Nov 4, 2022