gtfs_segments
create_segments(stop_df, parallel=False)
This function creates segments between stops based on their proximity and returns a GeoDataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_df |
GeoDataFrame
|
A pandas DataFrame containing information about stops on a transit network, including |
required |
their stop_id, coordinates, and trip_id.
Returns:
Type | Description |
---|---|
DataFrame
|
a GeoDataFrame with segments created from the input stop_df. |
Source code in gtfs_segments/gtfs_segments.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
filter_stop_df(stop_df, trip_ids, stop_loc_df)
It takes a dataframe of stops and a list of trip IDs and returns a dataframe of stops that are in the list of trip IDs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_df |
DataFrame
|
the dataframe of all stops |
required |
trip_ids |
Set
|
a list of trip_ids that you want to filter the stop_df by |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe with the trip_id, s top_id, and stop_sequence for the trips in the trip_ids list. |
Source code in gtfs_segments/gtfs_segments.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
get_gtfs_segments(path, agency_id=None, threshold=1, max_spacing=None, parallel=False)
The function get_gtfs_segments
takes a path to a GTFS feed file, an optional agency name, a
threshold value, and an optional maximum spacing value, and returns processed GTFS segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path parameter is the file path to the GTFS (General Transit Feed Specification) data. |
required |
This is the data format used by public transportation agencies to provide schedule and geographic
information about their services.
[Optional] agency_id: The agency_id of the transit agency for which you want to retrieve the bus feed. If this
parameter is not provided, the function will retrieve the bus feed for all transit agencies. You can pass
a list of agency_ids to retrieve the bus feed for multiple transit agencies.
[Optional] threshold: The threshold parameter is used to filter out bus trips that have fewer stops than the
specified threshold. Trips with fewer stops than the threshold will be excluded from the result.
Defaults to 1
[Optional] max_spacing: The max_spacing
parameter is used to specify the maximum distance between two
consecutive stops in a segment. If the distance between two stops exceeds the max_spacing
value,
the segment is split into multiple segments.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A GeoDataFrame containing information about the stops and segments in the feed with segments |
GeoDataFrame
|
smaller than the max_spacing values. Each row contains the following columns: |
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
Source code in gtfs_segments/gtfs_segments.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
inspect_feed(feed)
It checks to see if the feed has any bus routes and if it has a shape_id
column in the trips
table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feed |
Feed
|
The feed object that you want to inspect. |
required |
Returns:
Type | Description |
---|---|
str
|
A message |
Source code in gtfs_segments/gtfs_segments.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
merge_stop_geom(stop_df, stop_loc_df)
Merge the stop_loc_df with the stop_df, and then convert the result to a GeoDataFrame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_df |
DataFrame
|
a dataframe of stops |
required |
stop_loc_df |
DataFrame
|
a GeoDataFrame of the stops |
required |
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A GeoDataFrame |
Source code in gtfs_segments/gtfs_segments.py
146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
merge_trip_geom(trip_df, shape_df)
It takes a dataframe of trips and a dataframe of shapes, and returns a geodataframe of trips with the geometry of the shapes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trip_df |
DataFrame
|
a dataframe of trips |
required |
shape_df |
GeoDataFrame
|
a GeoDataFrame of the shapes.txt file |
required |
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A GeoDataFrame |
Source code in gtfs_segments/gtfs_segments.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
pipeline_gtfs(filename, url, bounds, max_spacing)
It takes a GTFS file, downloads it, reads it, processes it, and then outputs a bunch of files.
Let's go through the function step by step.
First, we define the function and give it a name. We also give it a few arguments:
- filename: the name of the file we want to save the output to.
- url: the url of the GTFS file we want to download.
- bounds: the bounding box of the area we want to analyze.
- max_spacing: the maximum spacing we want to analyze.
We then create a folder to save the output to.
Next, we download the GTFS file and save it to the folder we just created.
Then, we read the GTFS file using the get_bus_feed
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
the name of the file you want to save the output to |
required |
url |
str
|
the url of the GTFS file |
required |
bounds |
List
|
the bounding box of the area you want to analyze. This is in the format |
required |
[min_lat,min_lon,max_lat,max_lon] max_spacing: The maximum distance between stops that you want to consider.
Returns:
Type | Description |
---|---|
str
|
Success or Failure of the pipeline |
Source code in gtfs_segments/gtfs_segments.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
|
process_feed(feed, parallel=False, max_spacing=None)
The function process_feed
takes a feed and optional maximum spacing as input, performs various
data processing and filtering operations on the feed, and returns a GeoDataFrame containing the
processed data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feed |
Feed
|
The |
required |
It likely includes data such as shapes (geometric representations of routes), trips (sequences of
stops), stop times (arrival and departure times at stops), and stops (locations of stops).
[Optional] max_spacing: The max_spacing
parameter is an optional parameter that specifies the maximum
distance between stops. If provided, the function will filter out stops that are farther apart than
the specified maximum spacing.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A GeoDataFrame containing information about the stops and segments in the feed with segments smaller than the max_spacing values. |
Source code in gtfs_segments/gtfs_segments.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
process_feed_stops(feed)
It takes a GTFS feed, merges the trip and shape data, filters the stop_times data to only include the trips that are in the feed, merges the stop_times data with the stop data, creates a segment for each stop pair, gets the EPSG zone for the feed, creates a GeoDataFrame, and calculates the length of each segment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feed |
Feed
|
a GTFS feed object |
required |
max_spacing |
the maximum distance between stops in meters. If a stop is more than this distance |
required |
from the previous stop, it will be dropped.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A GeoDataFrame with the following columns: |
Source code in gtfs_segments/gtfs_segments.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|