Skip To Content

GTFS To Network Dataset Transit Sources

Summary

Converts one or more General Transit Feed Specification (GTFS) public transit datasets to a set of feature classes and tables that can be used when creating a network dataset. The output feature classes and tables represent the transit stops, lines, and schedules in the format defined by the Network Analyst public transit data model, which can be interpreted by the Public Transit evaluator in a network dataset.

The transit data model feature classes and tables produced by this tool are as follows:

  • Stops
  • LineVariantElements
  • Calendars
  • CalendarExceptions
  • Lines
  • LineVariants
  • Runs
  • ScheduleElements
  • Schedules

The output from this tool can be used as input to the Connect Network Dataset Transit Sources To Streets tool to prepare all necessary inputs for a transit-enabled network dataset. The complete workflow for creating such a network dataset is described in Create and use a network dataset with public transit data.

Usage

  • The data from all input GTFS datasets will be combined into the same set of output tables and feature classes. The typical motivation for using multiple input GTFS datasets is to model a metropolitan area, where multiple transit service providers operate in the same geographic area.

  • Each input GTFS dataset must contain the stops.txt, routes.txt, trips.txt, and stop_times.txt files, and either the calendar.txt or calendar_dates.txt file, or both. The frequencies.txt file will be used if it is present.

  • Although GTFS allows blank values for the arrival_time and departure_time fields in the stop_times.txt file, this tool requires all rows in the stop_times.txt file to have explicit values for arrival_time and departure_time. Exact times are required by the Network Analyst public transit data model for consumption by the Public Transit evaluator in the network dataset.

  • The tool constructs the Stops feature class using the latitude and longitude values from the stop_lat and stop_lon fields in the GTFS stops.txt file.

  • The tool constructs the LineVariantElements features by creating a straight line between each pair of stops that is directly connected by a transit trip.

    Note:

    The LineVariantElements features are not intended to represent the actual geographic paths taken by buses, trains, or other public transit vehicles but are instead representative of logical connections in the transit system. LineVariantElements features are not meant to be used for visualization. The Public Transit evaluator in the network dataset will use the public transit schedules to determine the travel time required to traverse a LineVariantElements feature, so its shape and length are irrelevant. However, you can optionally edit the shapes of the LineVariantElements features manually, but the features should not be split or merged.

  • If more than one GTFS route provides service between the same two stops, one LineVariantElements feature will be created per GTFS route_id providing the service. For example, if bus 10 and bus 47 both travel between the same two stops with no other stops in between, the tool will generate two LineVariantElements features, one for bus 10 and one for bus 47. These two line feature will be geographically coincident.

  • Because the public transit data model requires feature classes and tables with specific names, it is not possible to include more than one set of public transit data model feature classes and tables in the same geodatabase. The target feature dataset should not be contained in a geodatabase that already has another feature dataset containing public transit data model feature classes.

  • If the target feature dataset is in an enterprise geodatabase, it must not be versioned. Before running the tool, reconcile and post the data in the feature dataset, and unregister it as versioned.

Syntax

GTFSToNetworkDatasetTransitSources(in_gtfs_folders, target_feature_dataset)
ParameterExplanationData Type
in_gtfs_folders
[in_gtfs_folders,...]

One or more folders containing valid GTFS data. Each folder must contain the GTFS stops.txt, routes.txt, trips.txt, and stop_times.txt files and either the calendar.txt or calendar_dates.txt file, or both.

Folder
target_feature_dataset

The feature dataset where the transit-enabled network dataset will be created. The Stops and LineVariantElements feature classes created by this tool will be placed in this feature dataset, and the output tables created by this tool will be placed in this feature dataset's parent geodatabase.

The feature dataset can be in a file geodatabase or an enterprise geodatabase and can have any spatial reference. If the target feature dataset is in an enterprise geodatabase, it must not be versioned. The target feature dataset should not be contained in a geodatabase that already has another feature dataset containing public transit data model feature classes.

Feature Dataset

Derived Output

NameExplanationData Type
updated_target_feature_dataset

The feature dataset to which the new feature classes have been added.

Feature Dataset
output_stops

The Stops feature class for the Network Analyst public transit data model.

Feature Class
output_line_variant_elements

The LineVariantElements feature class for the Network Analyst public transit data model.

Feature Class
output_calendars

The Calendars table for the Network Analyst public transit data model.

Table
output_calendar_exceptions

The CalendarExceptions table for the Network Analyst public transit data model.

Table
output_lines

The Lines table for the Network Analyst public transit data model.

Table
output_line_variants

The LineVariants table for the Network Analyst public transit data model.

Table
output_runs

The Runs table for the Network Analyst public transit data model.

Table
output_schedule_elements

The ScheduleElements table for the Network Analyst public transit data model.

Table
output_schedules

The Schedules table for the Network Analyst public transit data model.

Table

Code sample

GTFSToNetworkDatasetTransitSources example 1 (Python window)

The following script demonstrates how to use the GTFSToNetworkDatasetTransitSources tool in the Python window.

fd_path = r"E:\TransitAnalysis\TransitNetwork.gdb\TransitNetwork"
arcpy.conversion.GTFSToNetworkDatasetTransitSources([r"E:\GTFS\Agency1", r"E:\GTFS\Agency2"], fd_path)
GTFSToNetworkDatasetTransitSources example 2 (stand-alone script)

The following stand-alone Python script demonstrates how the GTFSToNetworkDatasetTransitSources and ConnectNetworkDatasetTransitSourcesToStreets tools can be used together to create a transit-enabled network dataset.

import os
import arcpy
arcpy.CheckOutExtension("network")

gtfs_folders = [
    r"E:\GTFS\Agency1",
    r"E:\GTFS\Agency2"
]
streets_orig = r"E:\Data\StreetData.gdb\Streets"

working_folder = r"E:\TransitAnalysis"
nd_template = os.path.join(working_folder, "TransitNetworkTemplate.xml")
gdb_name = "TransitNetwork.gdb"
out_gdb = os.path.join(working_folder, gdb_name)
fd_name = "TransitNetwork"
fd_path = os.path.join(out_gdb, fd_name)
streets = os.path.join(fd_path, "Streets")
nd_name = "TransitNetwork_ND"
nd_path = os.path.join(fd_path, nd_name)

# Create a file geodatabase and feature dataset to store the network dataset
arcpy.management.CreateFileGDB(working_folder, gdb_name)
arcpy.management.CreateFeatureDataset(out_gdb, fd_name, arcpy.SpatialReference(4326))

# Copy the streets data into the feature dataset so it can be used by the network dataset
# If the original streets are not in the same spatial reference as the feature dataset, you might
# need to use the Project tool instead of Copy.
arcpy.management.Copy(streets_orig, streets)

# Convert the GTFS dataset into public transit data model tables and feature classes
arcpy.conversion.GTFSToNetworkDatasetTransitSources(gtfs_folders, fd_path)

# Connect the transit stops to the streets and create the rest of the data model feature classes
# Use an expression to connect transit stops only to streets where pedestrians are allowed.
where = "PedestriansAllowed = 1"
arcpy.conversion.ConnectNetworkDatasetTransitSourcesToStreets(fd_path, streets, "100 meters", where)

# Create the network dataset from a template
arcpy.na.CreateNetworkDatasetFromTemplate(nd_template, fd_path)

# Build the network dataset
arcpy.na.BuildNetwork(nd_path)

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics