Skip to content

A GTFS parsing library for Go. This is our fork with fixes that haven't been merged upstream yet.

License

Notifications You must be signed in to change notification settings

public-transport/gtfsparser

 
 

Repository files navigation

Go Report Card GoDoc

go gtfsparser

A complete*, easy to use parsing library for GTFS data. Implemented in go. Accepts folders containing GTFS files and ZIPs. Feeds are validated during parsing. ID references are transformed into pointer references where appropriate.

This is a fork from the gtfsparser I developed at geOps, containing some minor improvements. Because of some changes to member types, this is not a drop-in replacement for the geOps gtfsparser.

Usage

feed := gtfsparser.NewFeed()
error := feed.Parse("sample-feed.zip")

See feed.go for exported fields.

Example

Parsing of the GTFS example feed:

import (
	"github.com/public-transport/gtfsparser"
	"fmt"
)

func main() {
    feed := gtfsparser.NewFeed()

    feed.Parse("sample-feed.zip")

    fmt.Printf("Done, parsed %d agencies, %d stops, %d routes, %d trips, %d fare attributes\n\n", len(feed.Agencies), len(feed.Stops), len(feed.Routes), len(feed.Trips), len(feed.FareAttributes))

    for k, v := range feed.Stops {
        fmt.Printf("[%s] %s (@ %f,%f)\n", k, v.Name, v.Lat, v.Lon)
    }
}

Output

Done, parsed 1 agencies, 9 stops, 5 routes, 11 trips, 2 fare attributes

[BULLFROG] Bullfrog (Demo) (@ 36.881081,-116.817970)
[NADAV] North Ave / D Ave N (Demo) (@ 36.914894,-116.768211)
[NANAA] North Ave / N A Ave (Demo) (@ 36.914944,-116.761475)
[AMV] Amargosa Valley (Demo) (@ 36.641495,-116.400940)
[FUR_CREEK_RES] Furnace Creek Resort (Demo) (@ 36.425289,-117.133163)
[BEATTY_AIRPORT] Nye County Airport (Demo) (@ 36.868446,-116.784584)
[STAGECOACH] Stagecoach Hotel & Casino (Demo) (@ 36.915684,-116.751678)
[DADAN] Doing Ave / D Ave N (Demo) (@ 36.909489,-116.768242)
[EMSI] E Main St / S Irving St (Demo) (@ 36.905697,-116.762177)

*Known restrictions

Validation may not be 100% complete. Tests are missing.

License

GPL v2, see LICENSE

About

A GTFS parsing library for Go. This is our fork with fixes that haven't been merged upstream yet.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.7%
  • Makefile 0.3%