gtfs

package module
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: GPL-3.0 Imports: 14 Imported by: 3

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
├── calendar_dates.txt
├── calendar.txt
├── routes.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
│   ├── calendar_dates.txt
│   ├── routes.txt
│   ├── stops.txt
│   ├── stop_times.txt
│   ├── transfers.txt
│   └── trips.txt
└── gtfs2
    ├── agency.txt
    ├── calendar_dates.txt
    ├── calendar.txt
    ├── routes.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
	Routes     []Route
	Stops      []Stop
	StopsTimes []Stop
	Trips      []Trip
	Calendars  []Calendar
	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_url"`
	URL       string `csv:"route_desc"`
	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
)

Const used in GTFS

Variables

This section is empty.

Functions

func ArrayIn added in v2.0.7

func ArrayIn(target string, array []string) bool

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

func DumpEdgeTimetable

func DumpEdgeTimetable(edgeTimetable *EdgeTimetable, dirPath string, filter map[string]bool) error

func HHMMSS2Sec

func HHMMSS2Sec(str string) int

func I2AA

func I2AA(i int) string

func Sec2HHMMSS

func Sec2HHMMSS(t int) string

func Unzip added in v2.0.5

func Unzip(src, dest string) error

Types

type Agency

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

Agency -

type Calendar

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

Calendar -

type CalendarDate

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

CalendarDate -

type EdgeTimetable

type EdgeTimetable struct {
	Edges      []TimetableEdge
	Properties []TimetableEdgeProperty
	Stops      []Stop
}

type FareAttribute added in v2.0.2

type FareAttribute struct {
	FareId           string  `csv:"fare_id"`
	Price            float64 `csv:"price"`
	CurrentType      string  `csv:"currency_type"`
	PaymentMethod    int     `csv:"payment_method"`
	Transfers        int     `csv:"transfer"`
	AgencyId         string  `csv:"agency_id"`
	TransferDuration string  `csv:"transfer_duration"`
}

FareAttribute -

type FareRule added in v2.0.2

type FareRule struct {
	FareId        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 GTFS

type GTFS struct {
	Path           string          `json:"path"` // The path to the containing directory
	Agency         Agency          `json:"agency"`
	Agencies       []Agency        `json:"agencies"`
	Routes         []Route         `json:"routes"`
	Stops          []Stop          `json:"stops"`
	StopsTimes     []StopTime      `json:"stop_times"`
	Trips          []Trip          `json:"trips"`
	Calendars      []Calendar      `json:"calendars"`
	CalendarDates  []CalendarDate  `json:"calendar_dates"`
	Transfers      []Transfer      `json:"transfer"`
	FareAttributes []FareAttribute `json:"fare_attributes"`
	FareRules      []FareRule      `json:"fare_rules"`
}

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 LoadFromUnzipGTFS added in v2.0.5

func LoadFromUnzipGTFS(fileName string, filter map[string]bool) (*GTFS, 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

func (*GTFS) AddTransfer

func (g *GTFS) AddTransfer(connectRange float64, walkingSpeed float64, road *gm.Graph, numThread int) error

connectRange: 接続する停留所間の最大距離 walkingSpeed: 歩行速度(分速メートル) road: 地図データのグラフ numThread: 使用するスレッド数

func (*GTFS) AddTransferWithOSM

func (g *GTFS) AddTransferWithOSM(connectRange float64, walkingSpeed float64, osmFileName string, numThread int) error

func (*GTFS) ExtractByAgencyID added in v2.0.7

func (g *GTFS) ExtractByAgencyID(ids []string) *GTFS

agencyIDを基に絞り込む

func (*GTFS) ExtractByDate

func (g *GTFS) ExtractByDate(date time.Time) *GTFS

対象日のGTFSのみに絞り込む

func (*GTFS) ExtractByRouteIDs added in v2.0.7

func (g *GTFS) ExtractByRouteIDs(ids []string) *GTFS

routeIDを基に絞り込む

func (*GTFS) GTFS2TimeTableEdges

func (g *GTFS) GTFS2TimeTableEdges() (et *EdgeTimetable)

func (*GTFS) GetFareAttribute added in v2.0.2

func (g *GTFS) GetFareAttribute(fareId string) (FareAttribute, error)

func (*GTFS) GetFareAttributeFromOD added in v2.0.2

func (g *GTFS) GetFareAttributeFromOD(originId string, destinationId string, routeId string) (FareAttribute, error)

func (*GTFS) GetHeadSign

func (g *GTFS) GetHeadSign(tripId string, stopId string) string

func (*GTFS) GetRoute

func (g *GTFS) GetRoute(routeId string) Route

func (*GTFS) GetRoutePatterns

func (g *GTFS) GetRoutePatterns() (patterns []RoutePattern)

func (*GTFS) GetStop

func (g *GTFS) GetStop(stopID string) Stop

func (*GTFS) GetTrip

func (g *GTFS) GetTrip(tripId string) Trip

func (*GTFS) InitIndexMap added in v2.0.7

func (g *GTFS) InitIndexMap() *IndexMap

func (*GTFS) Sort

func (g *GTFS) Sort()

type IndexMap added in v2.0.7

type IndexMap struct {
	StopID2Index    map[string]int
	TripID2Index    map[string]int
	RouteID2Index   map[string]int
	AgencyID2Index  map[string]int
	ServiceID2Index map[string]int
	FareID2Index    map[string]int
}

type Route

type Route struct {
	ID        string `csv:"route_id" json:"route_id"`
	AgencyID  string `csv:"agency_id" json:"agency_id"`
	ShortName string `csv:"route_short_name" json:"route_short_name"`
	LongName  string `csv:"route_long_name" json:"route_long_name"`
	Type      int    `csv:"route_type" json:"route_type"`
	Desc      string `csv:"route_url" json:"route_url"`
	URL       string `csv:"route_desc" json:"route_desc"`
	Color     string `csv:"route_color" json:"route_color"`
	TextColor string `csv:"route_text_color" json:"route_text_color"`
}

Route -

type RoutePattern

type RoutePattern struct {
	Trips []TripTimetable
}

type Stop

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

Stop -

type StopTime

type StopTime struct {
	StopID       string `csv:"stop_id" json:"stop_id"`
	StopSeq      string `csv:"stop_sequence" json:"stop_sequence"`
	StopHeadSign string `csv:"stop_headsign" json:"stop_headsign"`
	TripID       string `csv:"trip_id" json:"trip_id"`
	Shape        int    `csv:"shape_dist_traveled" json:"shape_dist_traveled"`
	Departure    string `csv:"departure_time" json:"departure_time"`
	Arrival      string `csv:"arrival_time" json:"arrival_time"`
	PickupType   int    `csv:"pickup_type" json:"pickup_type"`
	DropOffType  int    `csv:"drop_off_type" json:"drop_off_type"`
}

StopTime -

type TimetableEdge

type TimetableEdge struct {
	TripId        string `csv:"trip_id"`
	FromStop      string `csv:"from_stop_id"`
	ToStop        string `csv:"to_stop_id"`
	DepartureTime string `csv:"departure_time"`
	ArrivalTime   string `csv:"arrival_time"`
	PickupType    int    `csv:"pickup_type"`
	DropOffType   int    `csv:"drop_off_type"`
	StopHeadSign  string `csv:"stop_head_sign"`
}

type TimetableEdgeProperty

type TimetableEdgeProperty struct {
	TripID      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"`
	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_url"`
	URL         string `csv:"route_desc"`
	Color       string `csv:"route_color"`
	TextColor   string `csv:"route_text_color"`
}

type Transfer

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

Transfer -

type Trip

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

Trip -

type TripTimetable

type TripTimetable struct {
	StopTimes  []StopTime
	Properties TimetableEdgeProperty
}

func GetTripTimetables

func GetTripTimetables(g *GTFS) (tripTimetables []TripTimetable)

Jump to

Keyboard shortcuts

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