gtfs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: MIT Imports: 6 Imported by: 0

README

gtfs

Build Status GoDoc

This package allows General Transit Feed Specification files to be read and manipulated from Go.

In addition to basic GTFS support, this package also supports the following Google Transit Extensions to GTFS:

Support for additional extensions may be added in the future.

Installation

All code can be downloaded with:

go get -u github.com/dpearson/gtfs

This package has no dependencies outside of the standard library.

License

MIT License

Copyright (c) 2018-2023 David Pearson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Overview

Package gtfs provides functionality for reading and manipulating General Transit Feed Specification files.

It supports all files and fields described in the GTFS specification.

Index

Constants

View Source
const DefaultRouteColor = "FFFFFF"

DefaultRouteColor is the default color for a route with no specified color.

View Source
const DefaultRouteTextColor = "000000"

DefaultRouteTextColor is the default text color for a route with no specified text color.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agency

type Agency struct {
	ID       string
	Name     string
	URL      string
	Timezone string
	Lang     string
	Phone    string
	FareURL  string
	Email    string
}

An Agency is a single agency from a GTFS file.

Fields correspond directly to columns in agency.txt.

type BikesAllowed

type BikesAllowed int

BikesAllowed indicates whether bikes are allowed on a trip.

const (
	// BikesAllowedUnknown means that no information on whether bikes are
	// allowed is available.
	BikesAllowedUnknown BikesAllowed = iota

	// BikesAllowedYes means that at least one bike may be brought on this trip.
	BikesAllowedYes

	// BikesAllowedNo means that no bikes are allowed on this trip.
	BikesAllowedNo
)

type DropoffType

type DropoffType int

DropoffType indicates the type of dropoff available at a stop.

const (
	// DropoffTypeRegular indicates that regularly scheduled dropoffs are
	// available.
	DropoffTypeRegular DropoffType = iota

	// DropoffTypeNone indicates that no dropoffs are available.
	DropoffTypeNone

	// DropoffTypePhoneAgency indicates that riders must phone the transit
	// agency to schedule dropoffs.
	DropoffTypePhoneAgency

	// DropoffTypeCoordinateWithDriver indicates that riders must coordinate
	// with the vehicle driver to schedule dropoffs.
	DropoffTypeCoordinateWithDriver
)

type Fare

type Fare struct {
	ID               string
	Price            string
	CurrencyType     string
	PaymentMethod    PaymentMethod
	Transfers        uint64
	TransferDuration uint64

	Routes           []*Route
	OriginZones      []string
	DestinationZones []string
	ContainsZones    []string
}

A Fare is a single fare type.

Fields correspond directly to columns in fares.txt.

type FeedInfo

type FeedInfo struct {
	PublisherName string
	PublisherURL  string
	Lang          string
	StartDate     string
	EndDate       string
	Version       string
	ContactEmail  string
	ContactURL    string
}

FeedInfo specifies global information about a GTFS feed.

Fields correspond directly to columns in feed_info.txt.

type GTFS

type GTFS struct {
	Agencies     []*Agency
	Stops        []*Stop
	Routes       []*Route
	Services     []*Service
	Shapes       []*Shape
	Trips        []*Trip
	Fares        []*Fare
	Transfers    []*Transfer
	FeedInfo     FeedInfo
	Translations []*Translation
	// contains filtered or unexported fields
}

GTFS represents a single GTFS feed.

func Load

func Load(filePath string) (*GTFS, error)

Load reads a GTFS feed, which is expected to be contained within a ZIP file, from filePath.

This function loads a GTFS file as permissively as possible (i.e. all errors that can be ignored are ignored). For full control over options used when parsing, use LoadWithOptions instead.

func LoadFromReader

func LoadFromReader(r *zip.Reader) (*GTFS, error)

LoadFromReader reads a GTFS feed from a *zip.Reader.

This function loads a GTFS file as permissively as possible (i.e. all errors that can be ignored are ignored). For full control over options used when parsing, use LoadWithOptions instead.

func LoadFromReaderWithOptions

func LoadFromReaderWithOptions(r *zip.Reader, opts ParsingOptions) (*GTFS, error)

LoadFromReaderWithOptions reads a GTFS feed from a *zip.Reader using the specified options when parsing.

func LoadWithOptions

func LoadWithOptions(filePath string, opts ParsingOptions) (*GTFS, error)

LoadWithOptions reads a GTFS feed, which is expected to be contained within a ZIP file, from filePath using the specified options when parsing.

func (*GTFS) Translate

func (g *GTFS) Translate(sourceStr, lang string) string

Translate translates a source string into the specified language.

If no translation is available, the original source string is returned.

type LocationType

type LocationType int

LocationType specifies the specific type of a stop.

const (
	// LocationTypeStop is a stop where passengers board or exit a vehicle.
	LocationTypeStop LocationType = iota

	// LocationTypeStation is a station containing at least one stop.
	LocationTypeStation

	// LocationTypeStationEntrance is the entrance to a station.
	LocationTypeStationEntrance
)

type ParsingOptions

type ParsingOptions struct {
	StrictMode bool
}

ParsingOptions specifies options used when parsing GTFS files.

type PaymentMethod

type PaymentMethod int

A PaymentMethod indicates where fares are paid.

const (
	// PaymentMethodOnBoard indicates that fares are paid on board the vehicle.
	PaymentMethodOnBoard PaymentMethod = iota

	//PaymentMethodBeforeBoarding indicates that fares are paid prior to
	// boarding the vehicle.
	PaymentMethodBeforeBoarding
)

type PickupType

type PickupType int

PickupType indicates the type of pickup available at a stop.

const (
	// PickupTypeRegular indicates that regularly scheduled pickups are
	// available.
	PickupTypeRegular PickupType = iota

	// PickupTypeNone indicates that no pickups are available.
	PickupTypeNone

	// PickupTypePhoneAgency indicates that riders must phone the transit agency
	// to schedule pickups.
	PickupTypePhoneAgency

	// PickupTypeCoordinateWithDriver indicates that riders must coordinate with
	// the vehicle driver to schedule pickups.
	PickupTypeCoordinateWithDriver
)

type Route

type Route struct {
	ID          string
	Agency      *Agency
	ShortName   string
	LongName    string
	Description string
	Type        RouteType
	URL         string
	Color       string
	TextColor   string
	SortOrder   uint64
}

A Route is a single route.

Fields correspond directly to columns in routes.txt.

type RouteType

type RouteType int

RouteType specifies the type of vehicles operating on a route.

const (
	// RouteTypeNotSpecified indicates that no route type was specified.
	RouteTypeNotSpecified RouteType = iota

	// RouteTypeLightRail indicates that the route is a light rail route.
	RouteTypeLightRail

	// RouteTypeSubway indicates that the route is a subway or metro route.
	RouteTypeSubway

	// RouteTypeRail indicates that the route is an intercity/long-distance rail
	// route.
	RouteTypeRail

	// RouteTypeBus indicates that the route is a bus route.
	RouteTypeBus

	// RouteTypeFerry indicates that the route is a ferry route.
	RouteTypeFerry

	// RouteTypeCableCar indicates that the route is a cable car route.
	RouteTypeCableCar

	// RouteTypeGondola indicates that the route is an aerial gondola route.
	RouteTypeGondola

	// RouteTypeFunicular indicates that the route is a funicular route.
	RouteTypeFunicular

	// RouteTypeTrolleybus indicates that the route is a trolleybus route.
	RouteTypeTrolleybus

	// RouteTypeMonorail indicates that the route is a monorail route.
	RouteTypeMonorail

	RouteTypeExtendedRailwayService
	RouteTypeExtendedHighSpeedRail
	RouteTypeExtendedLongDistanceRail
	RouteTypeExtendedInterRegionalRail
	RouteTypeExtendedCarTransportRail
	RouteTypeExtendedSleeperRail
	RouteTypeExtendedRegionalRail
	RouteTypeExtendedTouristRail
	RouteTypeExtendedRailShuttle
	RouteTypeExtendedSuburbanRail
	RouteTypeExtendedReplacementRail
	RouteTypeExtendedSpecialRail
	RouteTypeExtendedLorryTransportRail
	RouteTypeExtendedAllRail
	RouteTypeExtendedCrossCountryRail
	RouteTypeExtendedVehicleTransportRail
	RouteTypeExtendedRackAndPinionRail
	RouteTypeExtendedAdditionalRail

	RouteTypeExtendedCoachService
	RouteTypeExtendedInternationalCoach
	RouteTypeExtendedNationalCoach
	RouteTypeExtendedShuttleCoach
	RouteTypeExtendedRegionalCoach
	RouteTypeExtendedSpecialCoach
	RouteTypeExtendedSightseeingCoach
	RouteTypeExtendedTouristCoach
	RouteTypeExtendedCommuterCoach
	RouteTypeExtendedAllCoach

	RouteTypeExtendedUrbanRailService
	RouteTypeExtendedMetro
	RouteTypeExtendedUnderground
	RouteTypeExtendedUrbanRail
	RouteTypeExtendedAllUrbanRail
	RouteTypeExtendedMonorail

	RouteTypeExtendedBusService
	RouteTypeExtendedRegionalBusService
	RouteTypeExtendedExpressBusService
	RouteTypeExtendedStoppingBusService
	RouteTypeExtendedLocalBusService
	RouteTypeExtendedNightBusService
	RouteTypeExtendedPostBusService
	RouteTypeExtendedSpecialNeedsBusService
	RouteTypeExtendedMobilityBusService
	RouteTypeExtendedMobilityBusForRegisteredDisabledService
	RouteTypeExtendedSightseeingBus
	RouteTypeExtendedShuttleBus
	RouteTypeExtendedSchoolBus
	RouteTypeExtendedSchoolAndPublicServiceBus
	RouteTypeExtendedRailReplacementBusService
	RouteTypeExtendedDemandAndResponseBusService
	RouteTypeExtendedAllBusServices

	RouteTypeExtendedTrolleybusService

	RouteTypeExtendedTramService
	RouteTypeExtendedCityTramService
	RouteTypeExtendedLocalTramService
	RouteTypeExtendedRegionalTramService
	RouteTypeExtendedSightseeingTramService
	RouteTypeExtendedShuttleTramService
	RouteTypeExtendedAllTramServices

	RouteTypeExtendedWaterTransportService

	RouteTypeExtendedAirService

	RouteTypeExtendedFerryService

	RouteTypeExtendedAerialLiftService
	RouteTypeExtendedTelecabinService
	RouteTypeExtendedCableCarService
	RouteTypeExtendedElevatorService
	RouteTypeExtendedChairLiftService
	RouteTypeExtendedDragLiftService
	RouteTypeExtendedSmallTelecabinService
	RouteTypeExtendedAllTelecabinServices

	RouteTypeExtendedFunicularService

	RouteTypeExtendedTaxiService
	RouteTypeExtendedCommunalTaxiService
	RouteTypeExtendedWaterTaxiService
	RouteTypeExtendedRailTaxiService
	RouteTypeExtendedBikeTaxiService
	RouteTypeExtendedLicensedTaxiService
	RouteTypeExtendedPrivateHireServiceVehicle
	RouteTypeExtendedAllTaxiServices

	RouteTypeExtendedMiscellaneousService
	RouteTypeExtendedHorseDrawnCarriage
)

type Service

type Service struct {
	ID        string
	Monday    bool
	Tuesday   bool
	Wednesday bool
	Thursday  bool
	Friday    bool
	Saturday  bool
	Sunday    bool
	StartDate string
	EndDate   string

	AdditionalDates []string
	ExceptDates     []string
}

A Service is a schedule of service over one or more routes.

Fields correspond to columns in calendar.txt and calendar_dates.txt.

type Shape

type Shape struct {
	ID     string
	Points []*ShapePoint
}

A Shape is a collection of points describing a trip's path.

type ShapePoint

type ShapePoint struct {
	Latitude  float64
	Longitude float64
	Sequence  uint64
	Distance  float64
}

A ShapePoint is a single point in a larger shape.

type Stop

type Stop struct {
	ID                 string
	Code               string
	Name               string
	Description        string
	Latitude           float64
	Longitude          float64
	ZoneID             string
	URL                string
	LocationType       LocationType
	ParentStation      *Stop
	Timezone           string
	WheelchairBoarding string // TODO: parse me

	// Extensions:
	PlatformCode string
	VehicleType  RouteType
	// contains filtered or unexported fields
}

A Stop is a single stop served by an agency referenced in a GTFS feed.

Fields correspond directly to columns in stops.txt.

type StopTime

type StopTime struct {
	Stop                  *Stop
	ArrivalTime           string
	DepartureTime         string
	Sequence              uint64
	Headsign              string
	PickupType            PickupType
	DropoffType           DropoffType
	ShapeDistanceTraveled float64
	Timepoint             TimepointType
}

StopTime provides details on a specific stop in a trip.

type TimepointType

type TimepointType int

TimepointType specifies whether stop times are exact or approximate.

const (
	// TimepointTypeExact means that stop times are exact.
	TimepointTypeExact TimepointType = iota

	// TimepointTypeApproximate means that stop times are approximate.
	TimepointTypeApproximate
)

type Transfer

type Transfer struct {
	From                *Stop
	To                  *Stop
	Type                TransferType
	MinimumTransferTime uint64
}

A Transfer is specific transfer between two stops.

Fields correspond to columns in transfers.txt.

type TransferType

type TransferType int

TransferType specifies the specific type of a transfer.

const (
	// TransferTypeRecommended indicates a recommended transfer point between
	// two routes.
	TransferTypeRecommended TransferType = iota

	// TransferTypeTimed indicates that departures will wait for arriving
	// passengers.
	TransferTypeTimed

	// TransferTypeMinimumTime indicates that a minimum amount of time is
	// needed to transfer.
	//
	// Transfers with this type will have MinimumTransferTime set.
	TransferTypeMinimumTime

	// TransferTypeNone indicates that a transfer between those two stops is not
	// possible.
	TransferTypeNone
)

type Translation

type Translation struct {
	ID          string
	Language    string
	Translation string
}

A Translation is a single translation between an original string and another language.

For example, the following Translation:

Translation{
	ID:          "station-001",
	Language:    "en",
	Translation: "City Center",
}

would translate "station-001" to "City Center" in English.

Fields correspond directly to columns in translations.txt.

type Trip

type Trip struct {
	ID                   string
	Route                *Route
	Service              *Service
	Shape                *Shape
	Headsign             string
	ShortName            string
	DirectionID          string
	BlockID              string
	WheelchairAccessible WheelchairAccessible
	BikesAllowed         BikesAllowed

	AbsoluteTimes  bool
	StartTime      string
	EndTime        string
	HeadwaySeconds uint64
	ExactTimes     bool
	Stops          []*StopTime

	Exceptional bool
}

A Trip is a trip along a route with schedule information.

Fields correspond directly to columns in trips.txt, stop_times.txt, and frequencies.txt.

type WheelchairAccessible

type WheelchairAccessible int

WheelchairAccessible indicates whether a trip is accessible to passengers in wheelchairs.

const (
	// WheelchairAccessibleUnknown means that no wheelchair accessibility
	// information is available.
	WheelchairAccessibleUnknown WheelchairAccessible = iota

	// WheelchairAccessibleYes means that at least one passenger in a wheelchair
	// may be accommodated.
	WheelchairAccessibleYes

	// WheelchairAccessibleNo means that no passengers in wheelchairs may be
	// accommodated.
	WheelchairAccessibleNo
)

Jump to

Keyboard shortcuts

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