Skip to main content

A class-based instance designed for reading, converting, analyzing, and visualizing GTFS data

Project description

GTFS2GMNS

The open-source Python codes (GTFS2GMNS) is released to facilitate researchers and planners to construct the multi-modal transit networks easily from generic General Transit Feed Specification (GTFS) to the network modeling format in General Modeling Network Specification (GMNS). The converted physical and service networks in GMNS format are more convenient for network modeling tasks such as transit network routing, traffic flow assignment, simulation and service network optimization.

Your comments will be valuable for code review and improvement. Please feel free to add your comments to our Google document of GTFS2GMNS Users' Guide.

Getting Started

Download GTFS Data

On TransitFeed homepage, users can browse and download official GTFS feeds from around the world. Make sure that the following files are present, so that we can proceed.

  • stop.txt
  • route.txt
  • trip.txt
  • stop_times.txt
  • agency.txt

GTFS2GMNS can handle the transit data from several agencies. Users need to configure different sub-files in the same directory.

Main Steps

Read GTFS data

Step 1.1: Read routes.txt

  • route_id, route_long_name, route_short_name, route_url, route_type

Step 1.2: Read stop.txt

  • stop_id, stop_lat, stop_lon, direction, location_type, position, stop_code, stop_name, zone_id

Step 1.3: Read trips.txt

  • trip_id, route_id, service_id, block_id, direction_id, shape_id, trip_type
  • and create the directed_route_id by combining route_id and direction_id

Step 1.4: Read stop_times.txt

  • trip_id, stop_id, arrival_time, deaprture_time, stop_sequence

  • create directed_route_stop_id by combining directed_route_id and stop_id through the trip_id

    Note: the function needs to skip this record if trip_id is not defined, and link the virtual stop id with corresponding physical stop id.

  • fetch the geometry of the direction_route_stop_id

  • return the arrival_time for every stop

Building service network

Step 2.1 Create physical nodes

  • physical node is the original stop in standard GTFS

Step 2.2 Create directed route stop vertexes

  • add route stop vertexes. the node_id of route stop nodes starts from 100001

    Note: the route stop vertex the programing create nearby the corresponding physical node, to make some offset.

  • add entrance link from physical node to route stop node

  • add exit link from route stop node to physical node. As they both connect to the physical nodes, the in-station transfer process can be also implemented

Step 2.3 Create physical arcs

  • add physical links between each physical node pair of each trip

Step 2.4 Create service arcs

  • add service links between each route stop pair of each trip

Visualization

You can visualize generated networks using NeXTA or QGIS.

Quick Tutorial

Introducing Functional Tools within GTFS2GMNS

GTFS2GMNS is a Python package that serves as a class-based instance, specifically designed for reading, converting, analyzing, and visualizing GTFS data. The converted physical and service networks in GMNS format offer enhanced convenience for a variety of networkAg modeling tasks, including transit network routing, traffic flow assignment, simulation, and service network optimization.

Input for class GTFS2GMNS

  • gtfs_input_dir : str, the dir store GTFS data. GTFS2GMNS is capable of reading multiple GTFS data sets.
  • time_period: str, the time period sprcified (for data selection), default is "07:00:00_08:00:00"
  • date_period: list, user can specified exact data or dates for selection
  • gtfs_output_dir: str, the output folder to save data. defalut is ""
  • isSaveToCSV: bool, whether to save gmns node and link to local machine, default is True

Code Example

Loading gtfs data

from gtfs2gmns import GTFS2GMNS

if __name__ == "__main__":
    gtfs_input_dir = r"Your-Path-Folder-To-GTFS-Data"

    # Explain: GMNS2GMNS is capable of reading multiple GTFS data sets
    """
	--root folder
	    -- subfolder (GTFS data of agency 1)
	    -- subfolder (GTFS data of agency 2)
	    -- subfolder (GTFS data of agency 3)
	    -- ...
	then, assign gtfs_input_foler = root folder
    """

    time_period = "00:00:00_23:59:59"
    date_period = []

    gg = GTFS2GMNS(gtfs_input_dir, time_period, date_period, gtfs_output_dir="", isSaveToCSV=False)

Generate access line between zones to nodes

import gtfs2gmns as gg

path_zone = "Path to zone.csv"    # please make sure you have zone_id, x_coord, y_coord in columns
path_node = "Path to node.csv"    # please make sure you have node_id, x_coord, y_coord in columns

radius = 100 # unit in meters
k_closest = 0 # if 0, generate all accessible links within radius. if 1, closest link within the radius...

access_links = gg.generate_access_links(path_zone, path_node, radius, k_closest)

access_links.to_csv("access_link.csv", index=False)

Functions and Attributes

func_type func_name Python example Input Output Remark
read-show agency gg.agency NA DataFrame This attribute load and return agency data from source folder
calendar gg.calendar
calendar_dates
fare_attributes
fare_rules
feed_info
frequencies
routes
shapes
stops
stop_times
trips
transfers
timepoints
timepoint_times
trip_routes
stops_freq
routes_freq
rute_segments
route_segment_speed
vis_stops_freq
analysis vis_routes_fres
vis_route_segment_speed
vis_route_segment_runtime
vis_route_stop_speed_heatmap
vis_spacetime_trajectory
equity_alanysis
accessibility_analysis
load_gtfs
gen_gmns_node_link
visualization

Upcoming Features

  • Output service and trace files.
  • Set the time period and add vdf_fftt and vdf_freq fields in link files.
  • Add Visualization functions
    • Stops
    • Routes
    • ...

Citing gtfs2gmns

If you use gtfs2gmns in your research please use the following BibTeX entry:

@misc{gtfs2gmns,
  author =       {Fang Tang, Xiangyong Luo, Han Wang, Xuesong Zhou},
  title =        {Connecting Oasis for Transit Deserts: Mathematical Model and Reformulation for Equity-oriented Network Design},
  howpublished = {Github},
  year =         {2023},
  url =          {https://github.com/xyluo25/gtfs2gmns}
}
@misc{gtfs2gmns,
  author =       {Xiangyong Luo, Fang Tang, Han Wang, Xuesong Zhou},
  title =        {gtfs2gmns - A class-based instance designed for reading, converting, analyzing, and visualizing GTFS data.},
  howpublished = {Github},
  year =         {2023},
  url =          {https://github.com/xyluo25/gtfs2gmns}
}
Luo, X., Tang, F, Wang, H and Zhou, X. (2021, April 4). GTFS2GMNS. Retrieved from https://github.com/xyluo25/gtfs2gmns

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gtfs2gmns-0.2.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

gtfs2gmns-0.2.3-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file gtfs2gmns-0.2.3.tar.gz.

File metadata

  • Download URL: gtfs2gmns-0.2.3.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for gtfs2gmns-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a29b38693e297b97be84963765ba38eea25a74920d33c04756640ed28040004c
MD5 eecb9195e50a4458f5e1f4acc3a34914
BLAKE2b-256 c98a5fb31a86298d4a239164bd179527704c78588e79a21972cbb67305d90084

See more details on using hashes here.

File details

Details for the file gtfs2gmns-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: gtfs2gmns-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for gtfs2gmns-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 52b464d62d44d55cb18caefe21642b6b63ed7c06521dd0bd1d993e6c7f61bd00
MD5 837451f8070882442300a1f7a3a04643
BLAKE2b-256 6f4cc0071693508edbad51c2b07fc54e036908ac9e8d3c94a4edfc79bc065d3d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page