0
# GTFS Kit
1
2
A comprehensive Python library for analyzing General Transit Feed Specification (GTFS) data in memory without requiring a database. GTFS Kit leverages Pandas and GeoPandas for data processing and provides comprehensive functionality for working with public transit data including routes, stops, trips, shapes, and calendar information.
3
4
## Package Information
5
6
- **Package Name**: gtfs-kit
7
- **Language**: Python 3.10+
8
- **Installation**: `pip install gtfs-kit`
9
- **License**: MIT
10
11
## Core Imports
12
13
```python
14
import gtfs_kit as gk
15
```
16
17
## Basic Usage
18
19
```python
20
import gtfs_kit as gk
21
22
# Read a GTFS feed from a file or URL
23
feed = gk.read_feed('path/to/gtfs.zip', dist_units='km')
24
25
# Get basic information about the feed
26
print(gk.describe(feed))
27
28
# Get routes as a DataFrame
29
routes = gk.get_routes(feed)
30
31
# Get stops with geometry
32
stops = gk.get_stops(feed, as_gdf=True)
33
34
# Compute statistics for a specific date
35
date = '20230101'
36
route_stats = gk.compute_route_stats(feed, dates=[date])
37
stop_stats = gk.compute_stop_stats(feed, dates=[date])
38
39
# Export to GeoJSON
40
routes_geojson = gk.routes_to_geojson(feed)
41
stops_geojson = gk.stops_to_geojson(feed)
42
```
43
44
## Architecture
45
46
GTFS Kit is built around the `Feed` class which serves as the primary interface for all GTFS operations. The library is organized into functional modules:
47
48
- **Feed Operations**: Core data loading, manipulation, and export
49
- **Data Analysis**: Statistical analysis, time series, and performance metrics
50
- **Geospatial Operations**: Geometric processing, mapping, and spatial analysis
51
- **Data Processing**: Data cleaning, validation, and transformation utilities
52
- **Utilities**: Constants, helpers, and miscellaneous functions
53
54
All functions are available both as standalone functions and as methods on `Feed` instances, providing flexibility for different usage patterns.
55
56
## Capabilities
57
58
### Feed Operations
59
60
Core functionality for loading, manipulating, and exporting GTFS feeds. Includes the main `Feed` class and functions for reading feeds from files or URLs, listing feed contents, and writing feeds to various formats.
61
62
```python { .api }
63
def read_feed(path_or_url, dist_units='km'): ...
64
def list_feed(path): ...
65
66
class Feed:
67
def copy(self): ...
68
def to_file(self, path, ndigits=None): ...
69
```
70
71
[Feed Operations](./feed-operations.md)
72
73
### Data Analysis
74
75
Statistical analysis, time series computation, and performance metrics for transit operations. Provides comprehensive analysis capabilities for routes, stops, trips, and system-wide metrics across multiple dates and time periods.
76
77
```python { .api }
78
def compute_route_stats(feed, dates, **kwargs): ...
79
def compute_stop_stats(feed, dates, **kwargs): ...
80
def compute_trip_stats(feed, **kwargs): ...
81
def compute_route_time_series(feed, dates, **kwargs): ...
82
def compute_stop_time_series(feed, dates, **kwargs): ...
83
def compute_feed_stats(feed, dates, **kwargs): ...
84
```
85
86
[Data Analysis](./data-analysis.md)
87
88
### Geospatial Operations
89
90
Geometric processing, spatial analysis, and interactive mapping capabilities. Supports conversion between DataFrame and GeoDataFrame formats, spatial operations, and creation of interactive maps using Folium.
91
92
```python { .api }
93
def get_routes(feed, as_gdf=False, use_utm=False, **kwargs): ...
94
def get_stops(feed, as_gdf=False, use_utm=False, **kwargs): ...
95
def get_shapes(feed, as_gdf=False, use_utm=False): ...
96
def map_routes(feed, route_ids=None, **kwargs): ...
97
def map_stops(feed, stop_ids, **kwargs): ...
98
def routes_to_geojson(feed, route_ids=None, **kwargs): ...
99
def stops_to_geojson(feed, stop_ids=None): ...
100
```
101
102
[Geospatial Operations](./geospatial.md)
103
104
### Data Processing
105
106
Data cleaning, validation, and transformation utilities for improving GTFS data quality. Includes functions for cleaning IDs, times, route names, and comprehensive feed cleaning operations.
107
108
```python { .api }
109
def clean_ids(feed): ...
110
def clean_times(feed): ...
111
def clean_route_short_names(feed): ...
112
def clean(feed): ...
113
def drop_zombies(feed): ...
114
def aggregate_routes(feed, **kwargs): ...
115
def aggregate_stops(feed, **kwargs): ...
116
```
117
118
[Data Processing](./data-processing.md)
119
120
### Utilities
121
122
Constants, helper functions, and miscellaneous utilities for GTFS data manipulation. Includes date/time utilities, geometric calculations, data structure helpers, and configuration constants.
123
124
```python { .api }
125
# Constants
126
GTFS_REF: pd.DataFrame
127
DIST_UNITS: list
128
WGS84: str
129
COLORS_SET2: list
130
131
# Helper functions
132
def datestr_to_date(x, format_str='%Y%m%d', *, inverse=False): ...
133
def timestr_to_seconds(x, *, inverse=False, mod24=False): ...
134
def get_convert_dist(dist_units_in, dist_units_out): ...
135
def almost_equal(f, g): ...
136
```
137
138
[Utilities](./utilities.md)