GTFS To Network Dataset Transit Sources (Conversion)

Summary

Converts one or more General Transit Feed Specification (GTFS) public transit datasets to a set of feature classes and tables that represent the transit stops, lines, and schedules in the format defined by the Network Analyst public transit data model.

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

  • Stops
  • LineVariantElements
  • LVEShapes (optional)
  • 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 in which multiple transit service providers operate in the same geographic area.

  • The tool performs some validation on each input GTFS dataset to check for common data problems. When a problem is found, the tool issues a warning and does not process that dataset. The tool output will include data from only those input GTFS datasets that were successfully processed. If some GTFS datasets are processed successfully and others are not processed because of data problems, you can fix the data problems and append the fixed GTFS datasets to the existing tool output by running the tool again with the Append to existing tables parameter checked.

  • 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. The shapes.txt file will be used if it is present and you choose to output the LVEShapes feature class.

  • Although GTFS allows blank values for the arrival_time and departure_time fields in the stop_times.txt file, exact times are required by the Network Analyst public transit data model for consumption by the Public Transit evaluator in the network dataset. Check the Interpolate blank stop times parameter to estimate arrival and departure times for an input GTFS dataset with a stop_times.txt file that does not have explicit values for all arrival_time and departure_time fields.

  • 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 stop_lat and stop_lon fields in the GTFS stops.txt file define the latitude and longitude of stops. These fields are permitted by the specification to be null if the stop's location_type field has a value of 3 or 4. However, because this tool creates geographical features to represent stops, it cannot map stops that have no latitude or longitude. Consequently, stops with location_type values of 3 or 4 that have null values for stop_lat or stop_lon will be skipped and not included in the tool's output.

  • 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 edit the shapes of the LineVariantElements features manually, but do not split or merge the features or disconnect them from their adjacent stops.

    For cartographic visualization of public transit lines, you can use the Make LVEShapes from shapes.txt parameter to create the LVEShapes feature class from the shapes.txt file.

  • The tool takes longer to run when generating the optional LVEShapes feature class.

  • If more than one GTFS route provides service between the same two stops, one LineVariantElements feature will be created per GTFS route_id value 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, you cannot include more than one set of public transit data model feature classes and tables in the same geodatabase. Do not include the target feature dataset in a geodatabase with an existing 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.

Parameters

LabelExplanationData Type
Input 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, LineVariantElements, and LVEShapes 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. Do not include the target feature dataset in a geodatabase with an existing feature dataset containing public transit data model feature classes. Do not use a feature dataset in a mobile geodatabase if you intend to create a network dataset using the output.

Feature Dataset
Interpolate blank stop times
(Optional)

Specifies whether blank values from the arrival_time and departure_time fields in the GTFS stop_times.txt file will be interpolated when creating the public transit data model tables.

  • Checked—Blank values will be interpolated using simple linear interpolation. The original GTFS data will not be altered. If there are no blank values in the original data, no interpolation will occur.
  • Unchecked—Blank values will not be interpolated. If blank values are found in the input GTFS data, the tool will issue a warning and will not process the GTFS dataset. This is the default.
Boolean
Append to existing tables
(Optional)

Specifies whether the input GTFS datasets will be appended to existing public transit data model feature classes and tables in the target feature dataset and its parent geodatabase.

This parameter will be hidden if the target feature dataset and its parent geodatabase do not contain public transit data model feature classes and tables.

  • Checked—Data will be appended to the existing feature classes and tables.
  • Unchecked—Existing feature classes and tables will be overwritten. This is the default.
Boolean
Make LVEShapes from shapes.txt
(Optional)

Specifies whether the LVEShapes feature class will be created using the shapes.txt file in the GTFS dataset.

The LVEShapes feature class is not used by the network dataset for routing but can be used for improved output visualization with the Calculate Transit Service Frequency tool.

  • Checked—The LVEShapes feature class will be created.
  • Unchecked—The LVEShapes feature class will be not be created. This is the default.
Boolean

Derived Output

LabelExplanationData 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
Output LVEShapes

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

Feature Class

arcpy.conversion.GTFSToNetworkDatasetTransitSources(in_gtfs_folders, target_feature_dataset, {interpolate}, {append}, {make_lve_shapes})
NameExplanationData 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, LineVariantElements, and LVEShapes 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. Do not include the target feature dataset in a geodatabase with an existing feature dataset containing public transit data model feature classes. Do not use a feature dataset in a mobile geodatabase if you intend to create a network dataset using the output.

Feature Dataset
interpolate
(Optional)

Specifies whether blank values from the arrival_time and departure_time fields in the GTFS stop_times.txt file will be interpolated when creating the public transit data model tables.

  • INTERPOLATEBlank values will be interpolated using simple linear interpolation. The original GTFS data will not be altered. If there are no blank values in the original data, no interpolation will occur.
  • NO_INTERPOLATEBlank values will not be interpolated. If blank values are found in the input GTFS data, the tool will issue a warning and will not process the GTFS dataset. This is the default.
Boolean
append
(Optional)

Specifies whether the input GTFS datasets will be appended to existing public transit data model feature classes and tables in the target feature dataset and its parent geodatabase.

  • APPENDData will be appended to the existing feature classes and tables.
  • NO_APPENDExisting feature classes and tables will be overwritten. This is the default.
Boolean
make_lve_shapes
(Optional)

Specifies whether the LVEShapes feature class will be created using the shapes.txt file in the GTFS dataset.

The LVEShapes feature class is not used by the network dataset for routing but can be used for improved output visualization with the Calculate Transit Service Frequency tool.

  • MAKE_LVESHAPESThe LVEShapes feature class will be created.
  • NO_MAKE_LVESHAPESThe LVEShapes feature class will be not be created. This is the default.
Boolean

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
output_lve_shapes

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

Feature Class

Code sample

GTFSToNetworkDatasetTransitSources example 1 (Python window)

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

fd_path = r"E:\TransitAnalysis\TransitNetwork.gdb\TransitNetwork"
arcpy.transit.GTFSToPublicTransitDataModel([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.