Features To GTFS Shapes (Conversion)

Summary

Creates a shapes.txt file for a GTFS public transit dataset based on route line representations created by the Generate Shapes Features From GTFS tool.

The optional GTFS shapes.txt file contains a representation of the geographic paths taken by transit vehicles in a transit system. A good shapes.txt file is important for GTFS-based routing apps to display transit routes correctly on the map. Although many transit agencies generate their shapes.txt files using GPS trackers on their vehicles, other transit agencies lacking this hardware may have trouble creating this file.

This tool, together with the Generate Shapes Features From GTFS tool, allows you to create a shapes.txt file based on the stop, route, and schedule information from an existing GTFS dataset. After running the Generate Shapes Features From GTFS tool to estimate the paths traveled by vehicles in the transit system and fine-tuning the results based on local knowledge, you can run this tool to convert those line features into a new shapes.txt file. The tool also creates a new GTFS stop_times.txt file with the shape_dist_traveled field populated with values corresponding to the new shapes.

Usage

  • Most of the inputs to this tool should be the outputs from the Generate Shapes Features From GTFS tool. These two tools are intended to be used together.

  • The shape_dist_traveled field in the GTFS stop_times.txt file indicates how far along a transit line a particular stop is located. For example, if a bus drives 1.5 miles to reach the fifth stop along a route, the shape_dist_traveled value for that stop is 1.5. The shape_dist_traveled field should increase for each stop along the route. The distance traveled to the fifth stop should be greater than the distance traveled to the fourth stop and less than the distance traveled to the sixth stop, for example.

    The Features To GTFS Shapes tool uses a linear referencing procedure to calculate the shape_dist_traveled field values for stops. In some cases, the values calculated for sequential stops along the route may not be increasing. The tool will produce a warning message indicating which shapes, if any, have this problem. This problem usually occurs when the line geometry of the input shape overlaps itself or contains loops. Consequently, it is important to carefully review and edit the shape lines before running this tool to ensure that the shape lines are as clean and correct as possible. If a bus travels in both directions along the same street and overlaps itself on the centerline, it can help to slightly offset each direction of the shape line to either side of the centerline.

Syntax

FeaturesToGTFSShapes(in_shape_lines, in_shape_stops, in_gtfs_trips, in_gtfs_stop_times, out_gtfs_shapes, out_gtfs_stop_times, {distance_units})
ParameterExplanationData Type
in_shape_lines

A line feature class representing the GTFS shapes created by running the Generate Shapes Features From GTFS tool. The feature class must contain a shape_id field with values corresponding to the shape_id field values in the other tool inputs.

Feature Layer
in_shape_stops

A point feature class representing the GTFS stops associated with each shape created by running the Generate Shapes Features From GTFS tool. If a transit stop is used by multiple shapes, the stop should be duplicated in this feature class for each shape that uses it.

The feature class must contain a shape_id field with values corresponding to the shape_id field values in the other tool inputs. It must also contain a stop_id field with values corresponding to those in the shape_id column of the input GTFS stop_times.txt file.

Feature Layer
in_gtfs_trips

The updated GTFS trips.txt file created by running the Generate Shapes Features From GTFS tool. This file must have the shape_id column with values corresponding to those in the shape_id fields in the other tool inputs.

File
in_gtfs_stop_times

The original stop_times.txt file from the GTFS dataset that was used when running the Generate Shapes Features From GTFS tool.

File
out_gtfs_shapes

The output GTFS shapes.txt file.

File
out_gtfs_stop_times

The output GTFS stop_times.txt file This file will contain the shape_dist_traveled field with values derived from the new shapes.

File
distance_units
(Optional)

Specifies the distance units to use when populating the shape_dist_traveled field in the output GTFS files.

  • MILESThe unit is miles. This is the default.
  • METERSThe unit is meters
  • KILOMETERSThe unit is kilometers
String

Code sample

FeaturesToGTFSShapes example 1 (Python window)

This script shows how to run the FeaturesToGTFSShapes function in the Python window.

arcpy.conversion.FeaturesToGTFSShapes(
    r"C:\Data\GTFSShapes\GTFSShapes.gdb\Shapes",
    r"C:\Data\GTFSShapes\GTFSShapes.gdb\Stops",
    r"C:\Data\GTFSShapes\trips_new.txt",
    r"C:\Data\GTFS\stop_times.txt",
    r"C:\Data\GTFSShapes\shapes_new.txt",
    r"C:\Data\GTFSShapes\stop_times_new.txt",
    "Kilometers")

Environments

Random number generator

Only the seed portion of this environment variable is used. The generator type is ignored.

Licensing information

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

Related topics