gtfsparser

package module
v0.0.0-...-0f0c062 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2018 License: GPL-2.0 Imports: 15 Imported by: 0

README

Go Report Card Build Status 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/patrickbrosi/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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CsvParser

type CsvParser struct {
	Curline int
	// contains filtered or unexported fields
}

CsvParser is a wrapper around csv.Reader

func NewCsvParser

func NewCsvParser(file io.Reader) CsvParser

NewCsvParser creates a new CsvParser

func (*CsvParser) ParseRecord

func (p *CsvParser) ParseRecord() map[string]string

ParseRecord reads a single line into a map

type Feed

type Feed struct {
	Agencies       map[string]*gtfs.Agency
	Stops          map[string]*gtfs.Stop
	Routes         map[string]*gtfs.Route
	Trips          map[string]*gtfs.Trip
	Services       map[string]*gtfs.Service
	FareAttributes map[string]*gtfs.FareAttribute
	Shapes         map[string]*gtfs.Shape
	Transfers      []*gtfs.Transfer
	FeedInfos      []*gtfs.FeedInfo
	// contains filtered or unexported fields
}

Feed represents a single GTFS feed

func NewFeed

func NewFeed() *Feed

NewFeed creates a new, empty feed

func (*Feed) Parse

func (feed *Feed) Parse(path string) error

Parse the GTFS data in the specified folder into the feed

func (*Feed) SetParseOpts

func (feed *Feed) SetParseOpts(opts ParseOptions)

SetParseOpts sets the ParseOptions for this feed

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

A ParseError indicates an error during parsing

func (ParseError) Error

func (e ParseError) Error() string

type ParseOptions

type ParseOptions struct {
	UseDefValueOnError bool
	DropErroneous      bool
	DryRun             bool
}

A ParseOptions object holds options for parsing a the feed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL