gotransit

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

README

Interline gotransit

gotransit is a library and command-line tool for reading, writing, and processing transit data in GTFS and related formats. The library is structured as a set of data sources, filters, and transformations that can be mixed together in a variety of ways to create processing pipelines. The library supports the DMFR format to specify multiple input feeds.

Table of Contents

Installation

Download prebuilt binary

Linux and macOS binaries are attached to each release.

Install on MacOS using Homebrew

To install using the Gotransit formula for Homebrew:

brew install interline-io/gotransit/gotransit
To build from source
go get github.com/interline-io/gotransit

Main dependencies:

  • twpayne/go-geom
  • jmoiron/sqlx
  • Masterminds/squirrel
  • lib/pq
  • mattn/go-sqlite3 (see below)
Installing with SQLite Support

SQLite requires CGO support, and is not included in the static release builds. To enable support, compile locally with CGO_ENABLED=1.

Usage as a CLI tool

The main subcommands are:

validate command

The validate command performs a basic validation on a data source and writes the results to standard out.

$ gotransit validate --help
Usage: validate <reader>
  -ext value
    	Include GTFS Extension

Example:

$ gotransit validate "http://www.caltrain.com/Assets/GTFS/caltrain/CT-GTFS.zip"
copy command

The copy command performs a basic copy from a reader to a writer. By default, any entity with errors will be skipped and not written to output. This can be ignored with -allow-entity-errors to ignore simple errors and -allow-reference-errors to ignore entity relationship errors, such as a reference to a non-existent stop.

$ gotransit copy --help
Usage: copy <reader> <writer>
  -allow-entity-errors
    	Allow entities with errors to be copied
  -allow-reference-errors
    	Allow entities with reference errors to be copied
  -create
    	Create a basic database schema if none exists
  -ext value
    	Include GTFS Extension
  -fvid int
    	Specify FeedVersionID when writing to a database

Example:

$ gotransit copy --allow-entity-errors "http://www.caltrain.com/Assets/GTFS/caltrain/CT-GTFS.zip" output.zip

$ unzip -p output.zip agency.txt
agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url,agency_email
1000,Caltrain,http://www.caltrain.com,America/Los_Angeles,en,800-660-4287,,
extract command

The extract command extends the basic copy command with a number of additional options and transformations. It can be used to pull out a single route or trip, interpolate stop times, override a single value on an entity, etc. This is a separate command to keep the basic copy command simple while allowing the extract command to grow and add more features over time.

$ gotransit extract --help
Usage: extract <input> <output>
  -allow-entity-errors
    	Allow entities with errors to be copied
  -allow-reference-errors
    	Allow entities with reference errors to be copied
  -create
    	Create a basic database schema if none exists
  -create-missing-shapes
    	Create missing Shapes from Trip stop-to-stop geometries
  -ext value
    	Include GTFS Extension
  -extract-agency value
    	Extract Agency
  -extract-calendar value
    	Extract Calendar
  -extract-route value
    	Extract Route
  -extract-route-type value
    	Extract Routes matching route_type
  -extract-stop value
    	Extract Stop
  -extract-trip value
    	Extract Trip
  -fvid int
    	Specify FeedVersionID when writing to a database
  -interpolate-stop-times
    	Interpolate missing StopTime arrival/departure values
  -normalize-service-ids
    	Create Calendar entities for CalendarDate service_id's
  -set value
    	Set values on output; format is filename,id,key,value
  -use-basic-route-types
    	Collapse extended route_type's into basic GTFS values

Example:

# Extract a single trip from the Caltrain GTFS, and rename the agency to "caltrain".
$ gotransit extract -extract-trip 305 -set agency.txt,1000,agency_id,caltrain "http://www.caltrain.com/Assets/GTFS/caltrain/CT-GTFS.zip" output2.zip

# Note renamed agency
$ unzip -p output2.zip agency.txt
agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url,agency_email
caltrain,Caltrain,http://www.caltrain.com,America/Los_Angeles,en,800-660-4287,,

# Only entities related to the specified trip are included in the output.
$ unzip -p output2.zip trips.txt
route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,block_id,shape_id,wheelchair_accessible,bikes_allowed
12867,c_16869_b_19500_d_31,305,San Francisco Caltrain Station,305,0,,p_692594,0,0

$ unzip -p output2.zip routes.txt
route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color,route_sort_order
12867,caltrain,Bullet,Baby Bullet,,2,,E31837,ffffff,2

$ unzip -p output2.zip stop_times.txt
trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,shape_dist_traveled,timepoint
305,05:45:00,05:45:00,70261,1,,0,0,0.00000,1
305,06:01:00,06:01:00,70211,2,,0,0,17498.98397,1
305,06:09:00,06:09:00,70171,3,,0,0,27096.41601,1
305,06:19:00,06:19:00,70111,4,,0,0,42877.37732,1
305,06:28:00,06:28:00,70061,5,,0,0,53641.84115,1
305,06:47:00,06:47:00,70011,6,,0,0,75372.02742,1
dmfr command

under development

The dmfr command enables processing multiple feeds at once using a catalog in the Distributed Mobility Feed Registry format. It provides several additional subcommands for reading DMFR files, synchronizing these feeds to a database, downloading the latest versions of each feed, and automatically importing the feeds into a database. It provides the foundation for Transitland v2.

This command is still under active development and may change in future releases. Please see DMFR Command help.

Usage as a library

Key library components
  • Entity: An Entity is entity as specified by GTFS, such as an Agency, Route, Stop, etc.
  • Reader: A Reader provides streams of GTFS entities over channels. The gtcsv and gtdb modules provide CSV and Postgres/SQLite support, respectively.
  • Writer: A Writer accepts GTFS entities. As above, gtcsv and gtdb provide basic implementations. Custom writers can also be used to support non-GTFS outputs, such as building a routing graph.
  • Copier: A Copier reads a stream of GTFS entities from a Reader, checks each entity against a Marker, performs validation, applies any specified Filters, and sends to a Writer.
  • Marker: A Marker selects which GTFS entities will be processed by a Copier. For example, selecting only entities related to a single trip or route.
  • Filter: A Filter applies transformations to GTFS entities, such as converting extended route types to basic values, or modifying entity identifiers.
  • Extension: An Extension provides support for additional types of GTFS entities.
Example of how to use as a library

A simple example of reading and writing GTFS entities from CSV:

import (
	"fmt"

	"github.com/interline-io/gotransit"
	"github.com/interline-io/gotransit/copier"
	"github.com/interline-io/gotransit/gtcsv"
	"github.com/interline-io/gotransit/gtdb"
)

func main() {
	// Saves to a temporary file, removed upon Close().
	// Local paths to zip files and plain directories are also supported.
	url := "http://www.caltrain.com/Assets/GTFS/caltrain/CT-GTFS.zip"
	reader, err := gtcsv.NewReader(url)
	check(err)
	check(reader.Open())
	defer reader.Close()
	// Create a CSV writer
	// Writes to temporary directory, creates zip upon Close().
	writer, err := gtcsv.NewWriter("output.zip")
	check(err)
	check(writer.Open())
	// Copy from Reader to Writer.
	for stop := range reader.Stops() {
		fmt.Println("Read Stop:", stop.StopID)
		eid, err := writer.AddEntity(&stop)
		check(err)
		fmt.Println("Wrote Stop:", eid)
	}
	// Go ahead and close, check for errors
	check(writer.Close())
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}

Database support is handled similary:

func exampleDB(reader gotransit.Reader) {
	// Create a SQLite writer, in memory
	dburl := "sqlite3://:memory:"
	dbwriter, err := gtdb.NewWriter(dburl)
	check(err)
	check(dbwriter.Open())
	check(dbwriter.Create()) // Install schema.
	for stop := range reader.Stops() {
		// Preserves StopID but also assigns an integer ID (returned as string).
		fmt.Println("Read Stop:", stop.StopID)
		eid, err := dbwriter.AddEntity(&stop)
		check(err)
		fmt.Println("Wrote Stop:", eid)
	}
	// Read back from this source.
	dbreader, err := dbwriter.NewReader()
	check(err)
	for stop := range dbreader.Stops() {
		fmt.Println("Read Stop:", stop.StopID)
	}
	// Query database
}

More advanced operations can be performed using a Copier, which provides additional hooks for filtering, transformation, and validation:

func exampleCopier(reader gotransit.Reader) {
	writer, err := gtcsv.NewWriter("filtered.zip")
	check(err)
	check(writer.Open())
	defer writer.Close()
	cp := copier.NewCopier(reader, writer)
	result := cp.Copy()
	for _, err := range result.Errors {
		fmt.Println("Error:", err)
	}
	for fn, count := range result.EntityCount {
		fmt.Printf("Copied %d entities from %s\n", count, fn)
	}
}

See API docs at https://godoc.org/github.com/interline-io/gotransit

Included Readers and Writers

Target Module Supports Read Supports Write
CSV gtcsv
SQLite gtdb
Postgres (with PostGIS) gtdb

We welcome the addition of more readers and writers.

Development

gotransit follows Go coding conventions.

GitHub Actions runs all tests, stores code coverage reports as artifacts, and cuts releases using GoReleaser.

Releases

Releases follow Semantic Versioning conventions.

To cut a new release:

  1. Tag the master branch with the next SemVer version (for example: v0.2.0).
  2. GitHub Actions will run GoReleaser and create a GitHub release on this repository.

Licenses

gotransit is released under a "dual license" model:

  • open-source for use by all under the GPLv3 license
  • also available under a flexible commercial license from Interline

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterEntityFilter

func RegisterEntityFilter(name string)

RegisterEntityFilter registers a EntityFilter.

func RegisterExtension

func RegisterExtension(name string, factory extensionFactory)

RegisterExtension registers an Extension.

func RegisterReader

func RegisterReader(name string, factory readerFactory)

RegisterReader registers a Reader.

func RegisterWriter

func RegisterWriter(name string, factory writerFactory)

RegisterWriter registers a Writer.

func SecondsToString

func SecondsToString(secs int) string

SecondsToString takes seconds-since-midnight and returns a GTFS-style time.

func StringToSeconds

func StringToSeconds(value string) (int, error)

StringToSeconds parses a GTFS-style time and returns seconds since midnight.

func ValidateShapes

func ValidateShapes(shapes []Shape) []error

ValidateShapes returns errors for an array of shapes.

func ValidateStopTimes

func ValidateStopTimes(stoptimes []StopTime) []error

ValidateStopTimes checks if the trip follows GTFS rules.

Types

type Agency

type Agency struct {
	AgencyID       string `csv:"agency_id"`
	AgencyName     string `csv:"agency_name" required:"true"`
	AgencyURL      string `csv:"agency_url" required:"true"`
	AgencyTimezone string `csv:"agency_timezone" required:"true"`
	AgencyLang     string `csv:"agency_lang"`
	AgencyPhone    string `csv:"agency_phone"`
	AgencyFareURL  string `csv:"agency_fare_url"`
	AgencyEmail    string `csv:"agency_email"`
	BaseEntity
}

Agency agency.txt

func (*Agency) EntityID

func (ent *Agency) EntityID() string

EntityID returns the ID or AgencyID.

func (*Agency) Errors

func (ent *Agency) Errors() (errs []error)

Errors for this Entity.

func (*Agency) Filename

func (ent *Agency) Filename() string

Filename agency.txt

func (*Agency) TableName

func (ent *Agency) TableName() string

TableName gtfs_agencies

func (*Agency) Warnings

func (ent *Agency) Warnings() (errs []error)

Warnings for this Entity.

type BaseEntity

type BaseEntity struct {
	Timestamps
	ID            int
	FeedVersionID int
	// contains filtered or unexported fields
}

BaseEntity provides default methods.

func (*BaseEntity) AddError

func (ent *BaseEntity) AddError(err error)

AddError adds a loading error to the entity, e.g. from a CSV parse failure

func (*BaseEntity) AddWarning added in v0.4.10

func (ent *BaseEntity) AddWarning(err error)

AddWarning .

func (*BaseEntity) EntityID

func (ent *BaseEntity) EntityID() string

EntityID returns the entity ID.

func (*BaseEntity) Errors

func (ent *BaseEntity) Errors() []error

Errors returns validation errors.

func (*BaseEntity) Extra

func (ent *BaseEntity) Extra() map[string]string

Extra provides any additional fields that were present.

func (*BaseEntity) Filename

func (ent *BaseEntity) Filename() string

Filename returns the filename for this entity.

func (*BaseEntity) SetExtra

func (ent *BaseEntity) SetExtra(key string, value string)

SetExtra adds a string key, value pair to the entity's extra fields.

func (*BaseEntity) SetFeedVersionID

func (ent *BaseEntity) SetFeedVersionID(fvid int)

SetFeedVersionID sets the Entity's FeedVersionID.

func (*BaseEntity) SetID added in v0.1.1

func (ent *BaseEntity) SetID(id int)

SetID sets the integer ID.

func (*BaseEntity) UpdateKeys

func (ent *BaseEntity) UpdateKeys(emap *EntityMap) error

UpdateKeys updates entity referencespdates foreign keys based on an EntityMap.

func (*BaseEntity) Warnings

func (ent *BaseEntity) Warnings() []error

Warnings returns validation warnings.

type Calendar

type Calendar struct {
	ServiceID string    `csv:"service_id" required:"true"`
	Monday    int       `csv:"monday" required:"true"`
	Tuesday   int       `csv:"tuesday" required:"true"`
	Wednesday int       `csv:"wednesday" required:"true"`
	Thursday  int       `csv:"thursday" required:"true"`
	Friday    int       `csv:"friday" required:"true"`
	Saturday  int       `csv:"saturday" required:"true"`
	Sunday    int       `csv:"sunday" required:"true"`
	StartDate time.Time `csv:"start_date" required:"true"`
	EndDate   time.Time `csv:"end_date" required:"true"`
	Generated bool      `db:"generated"`
	BaseEntity
}

Calendar calendars.txt

func (*Calendar) EntityID

func (ent *Calendar) EntityID() string

EntityID returns the ID or ServiceID.

func (*Calendar) Errors

func (ent *Calendar) Errors() (errs []error)

Errors for this Entity.

func (*Calendar) Filename

func (ent *Calendar) Filename() string

Filename calendar.txt

func (*Calendar) TableName

func (ent *Calendar) TableName() string

TableName gtfs_calendars

func (*Calendar) Warnings

func (ent *Calendar) Warnings() (errs []error)

Warnings for this Entity.

type CalendarDate

type CalendarDate struct {
	ServiceID     string    `csv:"service_id" required:"true"`
	Date          time.Time `csv:"date" required:"true"`
	ExceptionType int       `csv:"exception_type" required:"true"`
	BaseEntity
}

CalendarDate calendar_dates.txt

func (*CalendarDate) EntityID

func (ent *CalendarDate) EntityID() string

EntityID returns nothing, CalendarDates are not unique.

func (*CalendarDate) Errors

func (ent *CalendarDate) Errors() (errs []error)

Errors for this Entity.

func (*CalendarDate) Filename

func (ent *CalendarDate) Filename() string

Filename calendar_dates.txt

func (*CalendarDate) TableName

func (ent *CalendarDate) TableName() string

TableName gtfs_calendar_dates

func (*CalendarDate) UpdateKeys

func (ent *CalendarDate) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

type Entity

type Entity interface {
	EntityID() string
	Filename() string
	Errors() []error
	Warnings() []error
	AddError(error)
	AddWarning(error)
	SetID(int)
	SetExtra(string, string)
	Extra() map[string]string
	UpdateKeys(*EntityMap) error
}

Entity provides an interface for GTFS entities.

type EntityError

type EntityError interface {
	Error() string
}

EntityError is an interface for GTFS Errors

type EntityFilter

type EntityFilter interface {
	Filter(Entity, *EntityMap) error
}

EntityFilter provides an interface for modifying an entity, e.g. before writing

func GetEntityFilter

func GetEntityFilter(name string) (EntityFilter, error)

GetEntityFilter returns a Transform.

type EntityMap

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

EntityMap stores correspondances between Entity IDs, e.g. StopID -> Stop's integer ID in a database.

func NewEntityMap

func NewEntityMap() *EntityMap

NewEntityMap returns a new EntityMap.

func (*EntityMap) Get

func (emap *EntityMap) Get(efn string, eid string) (string, bool)

Get gets directly by filename, eid

func (*EntityMap) GetEntity added in v0.1.1

func (emap *EntityMap) GetEntity(ent Entity) (string, bool)

GetEntity returns the new ID for an Entity.

func (*EntityMap) KeysFor added in v0.5.1

func (emap *EntityMap) KeysFor(efn string) []string

KeysFor returns the keys for a filename.

func (*EntityMap) Set

func (emap *EntityMap) Set(efn string, oldid string, newid string) error

Set directly adds an entry to the set.

func (*EntityMap) SetEntity added in v0.1.1

func (emap *EntityMap) SetEntity(ent Entity, oldid string, newid string) error

SetEntity sets the old and new ID for an Entity.

func (*EntityMap) Update

func (emap *EntityMap) Update(other EntityMap)

Update copies values from another EntityMap.

type Extension

type Extension interface {
	Create(Writer) error
	Entities() []Entity
}

Extension defines two methods that specify the Entities in an Extension and how to Create the necessary output structures, e.g. in a database.

func GetExtension

func GetExtension(name string) (Extension, error)

GetExtension returns an Extension.

type FareAttribute

type FareAttribute struct {
	FareID           string               `csv:"fare_id" required:"true"`
	Price            float64              `csv:"price" required:"true"`
	CurrencyType     string               `csv:"currency_type" required:"true"`
	PaymentMethod    int                  `csv:"payment_method" required:"true"`
	Transfers        string               `csv:"transfers"` // string, empty is meaningful
	AgencyID         OptionalRelationship `csv:"agency_id" `
	TransferDuration int                  `csv:"transfer_duration"`
	BaseEntity
}

FareAttribute fare_attributes.txt

func (*FareAttribute) EntityID

func (ent *FareAttribute) EntityID() string

EntityID returns the ID or FareID.

func (*FareAttribute) Errors

func (ent *FareAttribute) Errors() (errs []error)

Errors for this Entity.

func (*FareAttribute) Filename

func (ent *FareAttribute) Filename() string

Filename fare_attributes.txt

func (*FareAttribute) TableName

func (ent *FareAttribute) TableName() string

TableName gtfs_fare_attributes

func (*FareAttribute) UpdateKeys

func (ent *FareAttribute) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

type FareRule

type FareRule struct {
	FareID        string               `csv:"fare_id" required:"true"`
	RouteID       OptionalRelationship `csv:"route_id" `
	OriginID      string               `csv:"origin_id"`
	DestinationID string               `csv:"destination_id"`
	ContainsID    string               `csv:"contains_id"`
	BaseEntity
}

FareRule fare_rules.txt

func (*FareRule) EntityID

func (ent *FareRule) EntityID() string

EntityID returns nothing.

func (*FareRule) Errors

func (ent *FareRule) Errors() (errs []error)

Errors for this Entity.

func (*FareRule) Filename

func (ent *FareRule) Filename() string

Filename fare_rules.txt

func (*FareRule) TableName

func (ent *FareRule) TableName() string

TableName gtfs_fare_Rules

func (*FareRule) UpdateKeys

func (ent *FareRule) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

type Feed added in v0.3.1

type Feed struct {
	ID              int                 `json:"-"`
	FeedID          string              `json:"id" db:"onestop_id"`
	FeedNamespaceID string              `json:"feed_namespace_id"`
	Spec            string              `json:"spec"`
	URLs            FeedUrls            `json:"urls" db:"urls"`
	AssociatedFeeds FeedAssociatedFeeds `json:"-"` // `json:"associated_feeds"`
	Languages       FeedLanguages       `json:"languages,omitempty"`
	License         FeedLicense         `json:"license"`
	Authorization   FeedAuthorization   `json:"authorization" db:"auth"`
	OtherIDs        map[string]string   `json:"other_ids" db:"-"`
	IDCrosswalk     map[string]string   `json:"id_crosswalk" db:"-"`
	File            string              `json:"-"` // internal
	DeletedAt       OptionalTime        `json:"-"` // internal
	Timestamps      `json:"-"`          // internal
}

Feed listed in a parsed DMFR file

func (*Feed) EntityID added in v0.3.1

func (ent *Feed) EntityID() string

EntityID .

func (Feed) TableName added in v0.3.1

func (Feed) TableName() string

TableName .

type FeedAssociatedFeeds added in v0.3.1

type FeedAssociatedFeeds map[string]string

FeedAssociatedFeeds .

func (*FeedAssociatedFeeds) Scan added in v0.3.1

func (a *FeedAssociatedFeeds) Scan(value interface{}) error

Scan .

func (FeedAssociatedFeeds) Value added in v0.3.1

func (a FeedAssociatedFeeds) Value() (driver.Value, error)

Value .

type FeedAuthorization added in v0.3.1

type FeedAuthorization struct {
	Type      string `json:"type,omitempty"` // ["header", "basic_auth", "query_param", "path_segment"]
	ParamName string `json:"param_name,omitempty"`
	InfoURL   string `json:"info_url,omitempty"`
}

FeedAuthorization contains details about how to access a Feed.

func (*FeedAuthorization) Scan added in v0.3.1

func (a *FeedAuthorization) Scan(value interface{}) error

Scan .

func (FeedAuthorization) Value added in v0.3.1

func (a FeedAuthorization) Value() (driver.Value, error)

Value .

type FeedInfo

type FeedInfo struct {
	FeedPublisherName string       `csv:"feed_publisher_name" required:"true"`
	FeedPublisherURL  string       `csv:"feed_publisher_url" required:"true"`
	FeedLang          string       `csv:"feed_lang" required:"true"`
	FeedStartDate     OptionalTime `csv:"feed_start_date"`
	FeedEndDate       OptionalTime `csv:"feed_end_date"`
	FeedVersion       string       `csv:"feed_version" db:"feed_version_name"`
	BaseEntity
}

FeedInfo feed_info.txt

func (*FeedInfo) EntityID

func (ent *FeedInfo) EntityID() string

EntityID returns nothing.

func (*FeedInfo) Errors

func (ent *FeedInfo) Errors() (errs []error)

Errors for this Entity.

func (*FeedInfo) Filename

func (ent *FeedInfo) Filename() string

Filename feed_info.txt

func (*FeedInfo) TableName

func (ent *FeedInfo) TableName() string

TableName gtfs_feed_infos

type FeedLanguages added in v0.3.1

type FeedLanguages []string

FeedLanguages .

func (*FeedLanguages) Scan added in v0.3.1

func (a *FeedLanguages) Scan(value interface{}) error

Scan .

func (FeedLanguages) Value added in v0.3.1

func (a FeedLanguages) Value() (driver.Value, error)

Value .

type FeedLicense added in v0.3.1

type FeedLicense struct {
	SpdxIdentifier          string `json:"spdx_identifier,omitempty"`
	URL                     string `json:"url,omitempty"`
	UseWithoutAttribution   string `json:"use_without_attribution,omitempty"`
	CreateDerivedProduct    string `json:"create_derived_product,omitempty"`
	RedistributionAllowed   string `json:"redistribution_allowed,omitempty"`
	CommercialUseAllowed    string `json:"commercial_use_allowed,omitempty"`
	ShareAlikeOptional      string `json:"share_alike_optional,omitempty"`
	AttributionText         string `json:"attribution_text,omitempty"`
	AttributionInstructions string `json:"attribution_instructions,omitempty"`
}

FeedLicense describes the license and usage information for a Feed.

func (*FeedLicense) Scan added in v0.3.1

func (a *FeedLicense) Scan(value interface{}) error

Scan .

func (FeedLicense) Value added in v0.3.1

func (a FeedLicense) Value() (driver.Value, error)

Value .

type FeedUrls added in v0.3.1

type FeedUrls struct {
	StaticCurrent            string   `json:"static_current,omitempty"`
	StaticHistoric           []string `json:"static_historic,omitempty"`
	StaticPlanned            string   `json:"static_planner,omitempty"`
	RealtimeVehiclePositions string   `json:"realtime_vehicle_positions,omitempty"`
	RealtimeTripUpdates      string   `json:"realtime_trip_updates,omitempty"`
	RealtimeAlerts           string   `json:"realtime_alerts,omitempty"`
}

FeedUrls contains URL values for a Feed.

func (*FeedUrls) Scan added in v0.3.1

func (a *FeedUrls) Scan(value interface{}) error

Scan .

func (FeedUrls) Value added in v0.3.1

func (a FeedUrls) Value() (driver.Value, error)

Value .

type FeedVersion

type FeedVersion struct {
	ID                   int
	FeedID               int
	FeedType             string
	SHA1                 string
	SHA1Dir              string
	File                 string
	URL                  string
	EarliestCalendarDate time.Time
	LatestCalendarDate   time.Time
	FetchedAt            time.Time
	Timestamps
}

FeedVersion represents a single GTFS data source.

func NewFeedVersionFromReader added in v0.1.1

func NewFeedVersionFromReader(reader Reader) (FeedVersion, error)

NewFeedVersionFromReader returns a FeedVersion from a Reader.

func (*FeedVersion) EntityID added in v0.1.1

func (ent *FeedVersion) EntityID() string

EntityID .

func (*FeedVersion) TableName

func (ent *FeedVersion) TableName() string

TableName sets the table name prefix.

type Frequency

type Frequency struct {
	TripID      string   `csv:"trip_id" required:"true"`
	StartTime   WideTime `csv:"start_time" required:"true"`
	EndTime     WideTime `csv:"end_time" required:"true"`
	HeadwaySecs int      `csv:"headway_secs" required:"true"`
	ExactTimes  int      `csv:"exact_times"`
	BaseEntity
}

Frequency frequencies.txt

func (*Frequency) EntityID

func (ent *Frequency) EntityID() string

EntityID returns nothing.

func (*Frequency) Errors

func (ent *Frequency) Errors() (errs []error)

Errors for this Entity.

func (*Frequency) Filename

func (ent *Frequency) Filename() string

Filename frequencies.txt

func (*Frequency) TableName

func (ent *Frequency) TableName() string

TableName gtfs_frequencies

func (*Frequency) UpdateKeys

func (ent *Frequency) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

func (*Frequency) Warnings

func (ent *Frequency) Warnings() (errs []error)

Warnings for this Entity.

type Level added in v0.4.0

type Level struct {
	LevelID    string  `csv:"level_id" required:"true"`
	LevelIndex float64 `csv:"level_index" required:"true"`
	LevelName  string  `csv:"level_name"`
	BaseEntity
}

Level levels.txt

func (*Level) EntityID added in v0.4.0

func (ent *Level) EntityID() string

EntityID returns the ID or StopID.

func (*Level) Filename added in v0.4.0

func (ent *Level) Filename() string

Filename levels.txt

func (*Level) TableName added in v0.4.0

func (ent *Level) TableName() string

TableName ext_pathways_levels

type LineString

type LineString struct {
	Valid bool
	geom.LineString
}

LineString is an EWKB/SL encoded LineString

func NewLineStringFromFlatCoords

func NewLineStringFromFlatCoords(coords []float64) LineString

NewLineStringFromFlatCoords returns a new LineString from flat (3) coordinates

func (*LineString) Scan

func (g *LineString) Scan(src interface{}) error

Scan implements Scanner

func (LineString) Value

func (g LineString) Value() (driver.Value, error)

Value implements driver.Value

type OptionalKey added in v0.1.1

type OptionalKey struct {
	sql.NullInt64
}

OptionalKey is the same as sql.NullInt

type OptionalRelationship added in v0.1.1

type OptionalRelationship struct {
	Key   string
	Valid bool
}

OptionalRelationship is a nullable foreign key constraint, similar to sql.NullString

func (*OptionalRelationship) Int added in v0.5.1

func (r *OptionalRelationship) Int() int

Int try to convert key to int

func (*OptionalRelationship) IsZero added in v0.1.1

func (r *OptionalRelationship) IsZero() bool

IsZero returns if this is a zero value.

func (*OptionalRelationship) Scan added in v0.1.1

func (r *OptionalRelationship) Scan(src interface{}) error

Scan implements sql.Scanner

func (*OptionalRelationship) String added in v0.1.1

func (r *OptionalRelationship) String() string

func (OptionalRelationship) Value added in v0.1.1

func (r OptionalRelationship) Value() (driver.Value, error)

Value returns nil if empty

type OptionalTime added in v0.1.1

type OptionalTime struct {
	Time  time.Time
	Valid bool
}

OptionalTime is a nullable time, but can scan strings

func (*OptionalTime) IsZero added in v0.1.1

func (r *OptionalTime) IsZero() bool

IsZero returns if this is a zero value.

func (*OptionalTime) Scan added in v0.1.1

func (r *OptionalTime) Scan(src interface{}) error

Scan implements sql.Scanner

func (*OptionalTime) String added in v0.1.1

func (r *OptionalTime) String() string

func (OptionalTime) Value added in v0.1.1

func (r OptionalTime) Value() (driver.Value, error)

Value returns nil if empty

type Pathway added in v0.4.0

type Pathway struct {
	PathwayID           string  `csv:"pathway_id" required:"true"`
	FromStopID          string  `csv:"from_stop_id" required:"true"`
	ToStopID            string  `csv:"to_stop_id" required:"true"`
	PathwayMode         int     `csv:"pathway_mode" required:"true" min:"1" max:"7"`
	IsBidirectional     int     `csv:"is_bidirectional" required:"true" min:"0" max:"1"`
	Length              float64 `csv:"length" min:"0"`
	TraversalTime       int     `csv:"traversal_time" min:"0"`
	StairCount          int     `csv:"stair_count"`
	MaxSlope            float64 `csv:"max_slope"`
	MinWidth            float64 `csv:"min_width"`
	SignpostedAs        string  `csv:"signposted_as"`
	ReverseSignpostedAs string  `csv:"reversed_signposted_as"`
	BaseEntity
}

Pathway pathways.txt

func (*Pathway) EntityID added in v0.4.0

func (ent *Pathway) EntityID() string

EntityID returns the ID or StopID.

func (*Pathway) Filename added in v0.4.0

func (ent *Pathway) Filename() string

Filename pathways.txt

func (*Pathway) GetString added in v0.5.1

func (ent *Pathway) GetString(key string) (string, error)

GetString returns the string representation of an field.

func (*Pathway) TableName added in v0.4.0

func (ent *Pathway) TableName() string

TableName ext_pathway_pathways

func (*Pathway) UpdateKeys added in v0.4.0

func (ent *Pathway) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

type Point

type Point struct {
	Valid bool
	geom.Point
}

Point is an EWKB/SL encoded point

func NewPoint

func NewPoint(lon, lat float64) Point

NewPoint returns a Point from lon, lat

func (*Point) Scan

func (g *Point) Scan(src interface{}) error

Scan implements Scanner

func (Point) Value

func (g Point) Value() (driver.Value, error)

Value implements driver.Value

type Reader

type Reader interface {
	Open() error
	Close() error
	ValidateStructure() []error
	StopTimesByTripID(...string) chan []StopTime
	// Entities
	ReadEntities(c interface{}) error
	Stops() chan Stop
	StopTimes() chan StopTime
	Agencies() chan Agency
	Calendars() chan Calendar
	CalendarDates() chan CalendarDate
	FareAttributes() chan FareAttribute
	FareRules() chan FareRule
	FeedInfos() chan FeedInfo
	Frequencies() chan Frequency
	Routes() chan Route
	Shapes() chan Shape
	Transfers() chan Transfer
	Pathways() chan Pathway
	Levels() chan Level
	Trips() chan Trip
}

Reader defines an interface for reading entities from a GTFS feed.

func GetReader

func GetReader(driver string, dburl string) (Reader, error)

GetReader returns a Reader for the URL.

func MustOpenReaderOrExit added in v0.4.10

func MustOpenReaderOrExit(path string) Reader

MustOpenReaderOrExit is a helper that returns an opened a reader or exits.

func MustOpenReaderOrPanic added in v0.4.10

func MustOpenReaderOrPanic(path string) Reader

MustOpenReaderOrPanic is a helper that returns an opened reader or panics.

func NewReader

func NewReader(url string) (Reader, error)

NewReader uses the scheme prefix as the driver name, defaulting to csv.

type Route

type Route struct {
	RouteID        string `csv:"route_id" required:"true"`
	AgencyID       string `csv:"agency_id"`
	RouteShortName string `csv:"route_short_name"`
	RouteLongName  string `csv:"route_long_name"`
	RouteDesc      string `csv:"route_desc"`
	RouteType      int    `csv:"route_type" required:"true"`
	RouteURL       string `csv:"route_url"`
	RouteColor     string `csv:"route_color"`
	RouteTextColor string `csv:"route_text_color"`
	RouteSortOrder int    `csv:"route_sort_order"`
	BaseEntity
}

Route routes.txt

func (*Route) EntityID

func (ent *Route) EntityID() string

EntityID returns ID or RouteID.

func (*Route) Errors

func (ent *Route) Errors() (errs []error)

Errors for this Entity.

func (*Route) Filename

func (ent *Route) Filename() string

Filename routes.txt

func (*Route) TableName

func (ent *Route) TableName() string

TableName gtfs_routes

func (*Route) UpdateKeys

func (ent *Route) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

func (*Route) Warnings

func (ent *Route) Warnings() (errs []error)

Warnings for this Entity.

type Service

type Service struct {
	AddedDates  []time.Time
	ExceptDates []time.Time
	Calendar
}

Service is a Calendar / CalendarDate union.

func NewService

func NewService(c Calendar, cds ...CalendarDate) *Service

NewService returns a new Service.

func NewServicesFromReader added in v0.1.1

func NewServicesFromReader(reader Reader) []*Service

NewServicesFromReader returns

func (*Service) AddCalendarDate

func (s *Service) AddCalendarDate(cd CalendarDate)

AddCalendarDate adds a service exception.

func (*Service) IsActive

func (s *Service) IsActive(t time.Time) bool

IsActive returns if this Service period is active on a specified date.

func (*Service) ServicePeriod added in v0.1.1

func (s *Service) ServicePeriod() (time.Time, time.Time)

ServicePeriod returns the widest possible range of days with transit service, including service exceptions.

type Shape

type Shape struct {
	ShapeID           string     `csv:"shape_id" required:"true"`
	ShapePtLat        float64    `csv:"shape_pt_lat" db:"-" required:"true"`
	ShapePtLon        float64    `csv:"shape_pt_lon" db:"-" required:"true"`
	ShapePtSequence   int        `csv:"shape_pt_sequence" db:"-" required:"true"`
	ShapeDistTraveled float64    `csv:"shape_dist_traveled" db:"-"`
	Geometry          LineString `db:"geometry"`
	Generated         bool       `db:"generated"`
	BaseEntity
}

Shape shapes.txt

func NewShapeFromShapes

func NewShapeFromShapes(shapes []Shape) Shape

NewShapeFromShapes takes Shapes with single points and returns a Shape with linestring geometry. Any errors from the input errors, or errors such as duplicate sequences, are added as entity errors.

func (*Shape) EntityID

func (ent *Shape) EntityID() string

EntityID returns the ID or ShapeID.

func (*Shape) Errors

func (ent *Shape) Errors() (errs []error)

Errors for this Entity.

func (*Shape) Filename

func (ent *Shape) Filename() string

Filename shapes.txt

func (*Shape) SetString

func (ent *Shape) SetString(key string, value string) error

SetString provides a fast, non-reflect loading path.

func (*Shape) TableName

func (ent *Shape) TableName() string

TableName gtfs_shapes

func (*Shape) Warnings

func (ent *Shape) Warnings() (errs []error)

Warnings for this Entity.

type Stop

type Stop struct {
	StopID             string               `csv:"stop_id" required:"true"`
	StopName           string               `csv:"stop_name"` // conditionally required
	StopCode           string               `csv:"stop_code"`
	StopDesc           string               `csv:"stop_desc"`
	StopLat            float64              `csv:"stop_lat" db:"-"` // required handled below
	StopLon            float64              `csv:"stop_lon" db:"-"`
	ZoneID             string               `csv:"zone_id"`
	StopURL            string               `csv:"stop_url"`
	LocationType       int                  `csv:"location_type"`
	ParentStation      OptionalRelationship `csv:"parent_station"`
	StopTimezone       string               `csv:"stop_timezone"`
	WheelchairBoarding int                  `csv:"wheelchair_boarding"`
	LevelID            OptionalRelationship `csv:"level_id"`
	Geometry           Point                `db:"geometry"`
	BaseEntity
}

Stop stops.txt

func (*Stop) Coordinates

func (ent *Stop) Coordinates() [2]float64

Coordinates returns the stop lon,lat as a [2]float64

func (*Stop) EntityID

func (ent *Stop) EntityID() string

EntityID returns the ID or StopID.

func (*Stop) Errors

func (ent *Stop) Errors() (errs []error)

Errors for this Entity.

func (*Stop) Filename

func (ent *Stop) Filename() string

Filename stops.txt

func (*Stop) SetCoordinates

func (ent *Stop) SetCoordinates(p [2]float64)

SetCoordinates takes a [2]float64 and sets the Stop's lon,lat

func (*Stop) TableName

func (ent *Stop) TableName() string

TableName gtfs_stops

func (*Stop) UpdateKeys

func (ent *Stop) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

func (*Stop) Warnings

func (ent *Stop) Warnings() (errs []error)

Warnings for this Entity.

type StopTime

type StopTime struct {
	TripID            string  `csv:"trip_id"`
	ArrivalTime       int     `csv:"arrival_time" `
	DepartureTime     int     `csv:"departure_time" `
	StopID            string  `csv:"stop_id" required:"true"`
	StopSequence      int     `csv:"stop_sequence" required:"true" min:"0"`
	StopHeadsign      string  `csv:"stop_headsign"`
	PickupType        int     `csv:"pickup_type" min:"0" max:"3"`
	DropOffType       int     `csv:"drop_off_type" min:"0" max:"3"`
	ShapeDistTraveled float64 `csv:"shape_dist_traveled" min:"0"`
	Timepoint         int     `csv:"timepoint" min:"-1" max:"1"` // -1 for empty
	Interpolated      int     // gotransit interpolated times: 0 for provided, 1 interpolated // TODO: 1 for shape, 2 for straight-line
	BaseEntity
}

StopTime stop_times.txt

func (*StopTime) EntityID

func (ent *StopTime) EntityID() string

EntityID returns nothing.

func (*StopTime) Errors

func (ent *StopTime) Errors() []error

Errors for this Entity.

func (*StopTime) Filename

func (ent *StopTime) Filename() string

Filename stop_times.txt

func (*StopTime) GetString

func (ent *StopTime) GetString(key string) (string, error)

GetString returns the string representation of an field.

func (*StopTime) SetString

func (ent *StopTime) SetString(key, value string) error

SetString provides a fast, non-reflect loading path.

func (*StopTime) TableName

func (ent *StopTime) TableName() string

TableName gtfs_stop_times

func (*StopTime) UpdateKeys

func (ent *StopTime) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

type Timestamps added in v0.1.1

type Timestamps struct {
	CreatedAt time.Time
	UpdatedAt time.Time
}

Timestamps .

func (*Timestamps) UpdateTimestamps added in v0.1.1

func (ent *Timestamps) UpdateTimestamps()

UpdateTimestamps initializes or updates CreatedAt / UpdatedAt

type Transfer

type Transfer struct {
	FromStopID      string `csv:"from_stop_id" required:"true"`
	ToStopID        string `csv:"to_stop_id" required:"true"`
	TransferType    int    `csv:"transfer_type" required:"true"`
	MinTransferTime int    `csv:"min_transfer_time"`
	BaseEntity
}

Transfer transfers.txt

func (*Transfer) EntityID

func (ent *Transfer) EntityID() string

EntityID returns nothing, Transfers are not unique.

func (*Transfer) Errors

func (ent *Transfer) Errors() (errs []error)

Errors for this Entity.

func (*Transfer) Filename

func (ent *Transfer) Filename() string

Filename transfers.txt

func (*Transfer) TableName

func (ent *Transfer) TableName() string

TableName gtfs_transfers

func (*Transfer) UpdateKeys

func (ent *Transfer) UpdateKeys(emap *EntityMap) error

UpdateKeys updates entity references.

func (*Transfer) Warnings

func (ent *Transfer) Warnings() (errs []error)

Warnings for this Entity.

type Trip

type Trip struct {
	RouteID              string               `csv:"route_id" required:"true"`
	ServiceID            string               `csv:"service_id" required:"true"`
	TripID               string               `csv:"trip_id" required:"true"`
	TripHeadsign         string               `csv:"trip_headsign"`
	TripShortName        string               `csv:"trip_short_name"`
	DirectionID          int                  `csv:"direction_id"`
	BlockID              string               `csv:"block_id"`
	ShapeID              OptionalRelationship `csv:"shape_id"`
	WheelchairAccessible int                  `csv:"wheelchair_accessible"`
	BikesAllowed         int                  `csv:"bikes_allowed"`
	StopPatternID        int
	BaseEntity
}

Trip trips.txt

func (*Trip) EntityID

func (ent *Trip) EntityID() string

EntityID returns the ID or TripID.

func (*Trip) Errors

func (ent *Trip) Errors() (errs []error)

Errors for this Entity.

func (*Trip) Filename

func (ent *Trip) Filename() string

Filename trips.txt

func (*Trip) TableName

func (ent *Trip) TableName() string

TableName gtfs_trips

func (*Trip) UpdateKeys

func (ent *Trip) UpdateKeys(emap *EntityMap) error

UpdateKeys updates Entity references.

type WideTime

type WideTime struct {
	Seconds int
	Valid   bool
}

WideTime handles seconds since midnight, allows >24 hours.

func NewWideTime

func NewWideTime(value string) (wt WideTime, err error)

NewWideTime converts the csv string to a WideTime.

func (*WideTime) Scan added in v0.1.1

func (wt *WideTime) Scan(src interface{}) error

Scan implements sql.Scanner

func (*WideTime) String

func (wt *WideTime) String() string

func (WideTime) Value added in v0.1.1

func (wt WideTime) Value() (driver.Value, error)

Value implements driver.Value

type Writer

type Writer interface {
	Open() error
	Close() error
	Create() error
	Delete() error
	NewReader() (Reader, error)
	AddEntity(Entity) (string, error)
	AddEntities([]Entity) error
}

Writer writes a GTFS feed.

func GetWriter

func GetWriter(driver string, dburl string) (Writer, error)

GetWriter returns a Writer for the URL.

func MustOpenWriterOrExit added in v0.4.10

func MustOpenWriterOrExit(path string) Writer

MustOpenWriterOrExit is a helper that returns an opened a writer or exits.

func MustOpenWriterOrPanic added in v0.4.10

func MustOpenWriterOrPanic(path string) Writer

MustOpenWriterOrPanic is a helper that returns an opened writer or panics.

func NewWriter

func NewWriter(dburl string) (Writer, error)

NewWriter uses the scheme prefix as the driver name, defaulting to csv.

Directories

Path Synopsis
cmd
gotransit command
ext
internal
log
testreadme command

Jump to

Keyboard shortcuts

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