Skip to content
/ gtfs2nx Public

Convert GTFS feeds to realistic, routable NetworkX graph.

License

Notifications You must be signed in to change notification settings

ai4up/gtfs2nx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gtfs2nx

Create routable NetworkX graph with realistic transfer times from GTFS feeds. 🚌 🚆 🚡

How

  • Cleaning & preprocessing
    • Remove trips with unrealistic travel times and speeds
    • Fix trips contradictory stop sequences and departure times
  • Enable routability
    • Ensure each node belongs only to single route
    • Calculate average segment travel times
    • Calculate average stop headway and service frequency
    • Add edges for walking transfer between routes with realistic transfer time (walking time + headway / 2)

Install

pip install gtfs2nx

Usage

import gtfs2nx as gx

G = gx.transit_graph('path/to/GTFS-feed.zip')

Customize transit network:

G = gx.transit_graph(
    gtfs_paths='path/to/GTFS-feed.zip',
    time_window=('06:00', '08:00'),
    route_types=[700], # only buses
    walk_transfer_max_distance=400, # allow transfers with long walking distance
)

See the API docs for more details and the getting-started notebook for a small demo.

Exemplary NetworkX analysis

import networkx as nx

# access precomputed stop characteristics
frequency = nx.get_node_attributes(G, 'frequency')

# routing
route = nx.shortest_path(G, from_stop, to_stop, weight='weight')

# travel time to other stops
travel_times = nx.single_source_dijkstra_path_length(G, source=from_stop, weight='weight')

# centrality analysis
centrality = nx.closeness_centrality(G, distance='weight')

Further use cases

Development

Build from source using poetry:

poetry build
pip install dist/gtfs2nx-*.whl

Configure post-checkout hook for branch specific .gitignore files:

git config --local core.hooksPath .githooks/