gtfs

package module
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: GPL-3.0 Imports: 5 Imported by: 2

README

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

Documentation

Index

Constants

View Source
const (
	RouteTypeTram      = 0
	RouteTypeSubway    = 1
	RouteTypeRail      = 2
	RouteTypeBus       = 3
	RouteTypeFerry     = 4
	RouteTypeCableCar  = 5
	RouteTypeGondola   = 6
	RouteTypeFunicular = 7

	ExceptionTypeAdded   = 1
	ExceptionTypeRemoved = 2

	PaymentMethodOnBoard        = 0
	PaymentMethodBeforeBoarding = 1

	TransfersNotPermitted = 0
	TransfersAtMostOnce   = 1
	TransfersAtMostTwice  = 2

	AttributionHasNoRole = 0
	AttributionHasRole   = 1

	PathwayWalkway        = 1
	PathwayStairs         = 2
	PathwayMovingSidewalk = 3
	PathwayEscalator      = 4
	PathwayElevator       = 5
	PathwayFareGate       = 6
	PathwayExitGate       = 7

	PathwayUnidirectional = 0
	PathwayBidirectional  = 1
)

Const used in GTFS

Variables

This section is empty.

Functions

func Dump

func Dump(g *GTFS, dirPath string, filter map[string]bool) error

Dump GTFS data to an already existing directory @param g: GTFS struct to dump @param dirPath: Target directory @param filter: same as for load function @return error

Types

type Agency

type Agency struct {
	ID       string `csv:"agency_id"`
	Name     string `csv:"agency_name"`
	URL      string `csv:"agency_url"`
	Timezone string `csv:"agency_timezone"`
	Langue   string `csv:"agency_lang"`
	Phone    string `csv:"agency_phone"`
}

Agency -

type Attribution added in v1.2.0

type Attribution struct {
	ID               string `csv:"attribution_id"`
	AgencyID         string `csv:"agency_id"`
	RouteID          string `csv:"route_id"`
	TripID           string `csv:"trip_id"`
	OrganizationName string `csv:"organization_name"`
	IsProducer       int    `csv:"is_producer"`
	IsOperator       int    `csv:"is_operator"`
	IsAuthority      int    `csv:"is_authority"`
	Url              string `csv:"attribution_url"`
	Email            string `csv:"attribution_email"`
	Phone            string `csv:"attribution_phone"`
}

Attribution -

type Calendar

type Calendar struct {
	ServiceID string `csv:"service_id"`
	Monday    int    `csv:"monday"`
	Tuesday   int    `csv:"tuesday"`
	Wednesday int    `csv:"wednesday"`
	Thursday  int    `csv:"thursday"`
	Friday    int    `csv:"friday"`
	Saturday  int    `csv:"saturday"`
	Sunday    int    `csv:"sunday"`
	Start     string `csv:"start_date"`
	End       string `csv:"end_date"`
}

Calendar -

type CalendarDate

type CalendarDate struct {
	ServiceID     string `csv:"service_id"`
	Date          string `csv:"date"`
	ExceptionType int    `csv:"exception_type"`
}

CalendarDate -

type FareAttribute added in v1.2.0

type FareAttribute struct {
	ID               string  `csv:"fare_id"`
	Price            float64 `csv:"price"`
	CurrencyType     string  `csv:"currency_type"`
	PaymentMethod    int     `csv:"payment_method"`
	Transfers        int     `csv:"transfers"`
	AgencyID         string  `csv:"agency_id"`
	TransferDuration string  `csv:"transfer_duration"`
}

FareAttribute -

type FareRule added in v1.2.0

type FareRule struct {
	ID            string `csv:"fare_id"`
	RouteID       string `csv:"route_id"`
	OriginID      string `csv:"origin_id"`
	DestinationID string `csv:"destination_id"`
	ContainsID    string `csv:"contains_id"`
}

FareRule -

type FeedInfo added in v1.2.0

type FeedInfo struct {
	PublisherName   string `csv:"feed_publisher_name"`
	PublisherUrl    string `csv:"feed_publisher_url"`
	Language        string `csv:"feed_lang"`
	DefaultLanguage string `csv:"default_lang"`
	StartDate       string `csv:"feed_start_date"`
	EndDate         string `csv:"feed_end_date"`
	Version         string `csv:"feed_version"`
	ContactEmail    string `csv:"feed_contact_email"`
	ContactUrl      string `csv:"feed_contact_url"`
}

FeedInfo -

type Frequency added in v1.2.0

type Frequency struct {
	TripId         string `csv:"trip_id"`
	StartTime      string `csv:"start_time"`
	EndTime        string `csv:"end_time"`
	HeadwaySeconds uint32 `csv:"headway_secs"`
	ExactTimes     string `csv:"exact_times"`
}

Frequency -

type GTFS

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
}

GTFS -

func Load

func Load(dirPath string, filter map[string]bool) (*GTFS, error)

Load - load GTFS files @param dirPath: the directory containing the GTFS @param filter: It is possible to partialy load the gtfs files If you don't want to load all the files, add an param to the Load function containing only the files that must be loaded Example: Load("path/to/gtfs", map[string]bool{"routes": true}) @return a filled GTFS or an error

func LoadSplitted

func LoadSplitted(dirPath string, filter map[string]bool) ([]*GTFS, error)

LoadSplitted - load splitted GTFS files ==> When GTFS are splitted into sub directories @param dirPath: the directory containing the sub GTFSs @param filter: see Load function @return an array of filled GTFS or an error

type Level added in v1.2.0

type Level struct {
	ID    string  `csv:"level_id"`
	Index float64 `csv:"level_index"`
	Name  string  `csv:"level_name"`
}

Level -

type Pathway added in v1.2.0

type Pathway struct {
	ID                   string  `csv:"pathway_id"`
	FromStopID           string  `csv:"from_stop_id"`
	ToStopID             string  `csv:"to_stop_id"`
	PathwayMode          int     `csv:"pathway_mode"`
	IsBidirectional      int     `csv:"is_bidirectional"`
	Length               float64 `csv:"length"`
	TraversalTime        uint32  `csv:"traversal_time"`
	StairCount           int     `csv:"stair_count"`
	MaxSlope             float64 `csv:"max_slope"`
	MinWidth             float64 `csv:"min_width"`
	SignpostedAs         string  `csv:"signposted_as"`
	ReversedSignpostedAs string  `csv:"reversed_signposted_as"`
}

Pathway -

type Route

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"`
}

Route -

type Shape added in v1.2.0

type Shape struct {
	ID               string  `csv:"shape_id"`
	PointLatitude    float64 `csv:"shape_pt_lat"`
	PointLongitude   float64 `csv:"shape_pt_lon"`
	PointSequence    int64   `csv:"shape_pt_sequence"`
	DistanceTraveled float64 `csv:"shape_dist_traveled"`
}

Shape -

type Stop

type Stop struct {
	ID          string  `csv:"stop_id"`
	Code        string  `csv:"stop_code"`
	Name        string  `csv:"stop_name"`
	Description string  `csv:"stop_desc"`
	Latitude    float64 `csv:"stop_lat"`
	Longitude   float64 `csv:"stop_lon"`
	Type        string  `csv:"location_type"`
	Parent      string  `csv:"parent_station"`
	ZoneId      string  `csv:"zone_id"`
}

Stop -

type StopTime

type StopTime struct {
	StopID       string  `csv:"stop_id"`
	StopSeq      uint32  `csv:"stop_sequence"`
	StopHeadSign string  `csv:"stop_headsign"`
	TripID       string  `csv:"trip_id"`
	Shape        float64 `csv:"shape_dist_traveled"`
	Departure    string  `csv:"departure_time"`
	Arrival      string  `csv:"arrival_time"`
}

StopTime -

type Transfer

type Transfer struct {
	FromStopID string `csv:"from_stop_id"`
	ToStopID   string `csv:"to_stop_id"`
	Type       int    `csv:"transfer_type"`
	MinTime    int    `csv:"min_transfer_time"`
}

Transfer -

type Trip

type Trip struct {
	ID          string `csv:"trip_id"`
	Name        string `csv:"trip_short_name"`
	RouteID     string `csv:"route_id"`
	ServiceID   string `csv:"service_id"`
	ShapeID     string `csv:"shape_id"`
	DirectionID string `csv:"direction_id"`
	Headsign    string `csv:"trip_headsign"`
}

Trip -

Jump to

Keyboard shortcuts

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