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 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 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 skips processing that dataset. The tool output will only include data from those input GTFS datasets that were successfully processed. If some GTFS datasets are processed successfully and others are skipped 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 set to True.

  • 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, exact times are required by the Network Analyst public transit data model for consumption by the Public Transit evaluator in the network dataset. Set the Interpolate blank stop times parameter to True 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 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

arcpy.conversion.GTFSToNetworkDatasetTransitSources(in_gtfs_folders, target_feature_dataset, {interpolate}, {append})
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
interpolate
(Optional)

Specifies whether to interpolate blank values from the arrival_time and departure_time fields in the GTFS stop_times.txt file 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 were 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 to append the input GTFS datasets to existing public transit data model feature classes and tables in the target feature dataset and its parent geodatabase.

  • APPENDData will be appended into the existing feature classes and tables.
  • NO_APPENDExisting feature classes and tables will be overwritten. 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

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: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics