• Stars
    star
    38
  • Rank 682,757 (Top 14 %)
  • Language
    Go
  • License
    GNU General Publi...
  • Created almost 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Load GTFS files in golang

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 ! :)