šŸ“š go-gtfs - Awesome Go Library for File Handling

Go Gopher mascot for go-gtfs

Load gtfs files in go.

šŸ·ļø File Handling
šŸ“‚ Libraries for handling files and file systems.
ā­ 44 stars
View on GitHub šŸ”—

Detailed Description of go-gtfs

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
ā”œā”€ā”€ attributions.txt
ā”œā”€ā”€ calendar_dates.txt
ā”œā”€ā”€ calendar.txt
ā”œā”€ā”€ fare_attributes.txt
ā”œā”€ā”€ fare_rules.txt
ā”œā”€ā”€ feed_info.txt
ā”œā”€ā”€ frequencies.txt
ā”œā”€ā”€ levels.txt
ā”œā”€ā”€ pathways.txt
ā”œā”€ā”€ routes.txt
ā”œā”€ā”€ shapes.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
ā”‚   ā”œā”€ā”€ attributions.txt
ā”‚   ā”œā”€ā”€ calendar_dates.txt
ā”‚   ā”œā”€ā”€ calendar.txt
ā”‚   ā”œā”€ā”€ fare_attributes.txt
ā”‚   ā”œā”€ā”€ fare_rules.txt
ā”‚   ā”œā”€ā”€ feed_info.txt
ā”‚   ā”œā”€ā”€ frequencies.txt
ā”‚   ā”œā”€ā”€ levels.txt
ā”‚   ā”œā”€ā”€ pathways.txt
ā”‚   ā”œā”€ā”€ routes.txt
ā”‚   ā”œā”€ā”€ shapes.txt
ā”‚   ā”œā”€ā”€ stops.txt
ā”‚   ā”œā”€ā”€ stop_times.txt
ā”‚   ā”œā”€ā”€ transfers.txt
ā”‚   ā””ā”€ā”€ trips.txt
ā””ā”€ā”€ gtfs2
    ā”œā”€ā”€ agency.txt
    ā”œā”€ā”€ attributions.txt
    ā”œā”€ā”€ calendar_dates.txt
    ā”œā”€ā”€ calendar.txt
    ā”œā”€ā”€ fare_attributes.txt
    ā”œā”€ā”€ fare_rules.txt
    ā”œā”€ā”€ feed_info.txt
    ā”œā”€ā”€ frequencies.txt
    ā”œā”€ā”€ levels.txt
    ā”œā”€ā”€ pathways.txt
    ā”œā”€ā”€ routes.txt
    ā”œā”€ā”€ shapes.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
	Agencies       []Agency
	Attributions   []Attribution
	Calendars      []Calendar
	CalendarDates  []CalendarDate
	FareAttributes []FareAttribute
	FareRules      []FareRule
	FeedInfos      []FeedInfo
	Frequencies    []Frequency
	Levels         []Level
	Routes         []Route
	Pathways       []Pathway
	Shapes         []Shape
	Stops          []Stop
	StopsTimes     []StopTime
	Trips          []Trip
	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_desc"`
	URL       string `csv:"route_url"`
	Color     string `csv:"route_color"`
	TextColor string `csv:"route_text_color"`
}

...

Contributions

Pull requests are welcome ! :)