Routes and route stop patterns

Transitland models route geometries by breaking them into individual components called RouteStopPatterns, or sometimes RSPs. RouteStopPatterns are uniquely defined by a route, a stop pattern, and a line geometry; all three derived from the trip routes, trip stop sequences, and shapes of a GTFS feed. Because of this, it is possible to have two distinct RouteStopPatterns within one route, both sharing the same line geometry but having different stop patterns, and vice versa. Individual RouteStopPatterns also have records of the GTFS trips and the single shape used to create them; a typical RouteStopPattern will reference back to one or many trips having the same stop pattern, but only references the one shape shared by those trips. When a RouteStopPattern's trips have no shapes or empty shapes, there will be no shape reference.

RouteStopPatterns may also modify the original shape line geometry if necessary. When this is done, a Boolean value named `is_modified` will be set to true. Currently, the line geometry is only modified when it is generated as the result of missing its original GTFS shape id or shape points. In this case, the line geometry becomes the sequential points of the stop pattern, and a separate boolean named `is_generated` will be set to true.

RouteStopPattern Data Model

Attribute Type Description
onestop_id Onestop ID RouteStopPattern
route_onestop_id Onestop ID Route
geometry Geography LineString
stop_pattern Onestop ID array List of stops along geometry in trip order. Stops may reappear.
stop_distances Number array List of distances in meters of stop_pattern stops along geometry.
identifiers String array List of identifiers.
trips String array List of trip ids
tags Hstore Associated shape id
is_modified Boolean Geometry has added or removed coordinates from the original shape
is_generated Boolean Geometry has been created because the original shape reference or coordinates are missing. Currently, geometries are auto-generated solely from the stop points.

Onestop ID

RouteStopPatterns are uniquely identified by a Onestop Id, but the composition of this id is different from that of Route, Stop, Feed, and Operator Onestop Ids. The RouteStopPattern Onestop Id has 5 components instead of 3, with each component separated by a dash just as the ids of the latter Transitland entities. The first 3 components are exactly the Route Onestop Id of the Route to which the RouteStopPattern belongs to. The fourth component is the first 6 hexadecimal characters of the MD5 hash produced from the stop pattern string (stop onestop id's separated by comma). The fifth component is the first 6 hexadecimal characters of the MD5 hash produced from geometry coordinates as a string (coordinates separated by comma).

Distance calculation algorithm

Each ScheduleStopPair will be associated to a RouteStopPattern. In addition, two attributes have been added to ScheduleStopPair: origin_distance_traveled and destination_distance_traveled. These are the distances, in meters rounded to the nearest decimeter, of the origin and destination stops along the line geometry from the start point.

The algorithm to compute these distances runs as follows:

  1. Set integer values a, b, and c to 0. These will correspond to index values of segments in a list.
  2. For each stop in the RouteStopPattern:
    1. If this stop (the current stop) is the first stop, and is found to lie before the geometry, set the distance to 0.0 m and continue.
    2. If this stop is the last stop and is found to lie after the geometry, set the distance to the length of the line and end the stop iteration.
  3. Otherwise, gather the list of segments of the line. Let:
    1. a = the index of the nearest matching segment for the previous stop. Keep a at 0 if the current stop is the first.
    2. c = the index of the nearest matching segment for the next stop, between the segment at a and the last line segment, inclusive. Let c = the index of the last segment if the current stop matches any of these characteristics:
      • is the last stop in the sequence
      • is the penultimate stop, and the next and last stop lies after the geometry
      • has a next stop that is an outlier (further than 100 m away from the line)
    3. Calculate b, the index of the nearest matching segment between a and c, inclusive.
    4. With b, calculate the nearest point on the segment from the current stop, and then calculate the distance along the line to the nearest point by adding the distances of the segments up to, but not including, b, and the distance from the end of the segment before b to the nearest point.
    5. If the computed distance is less than the previous stop's computed distance, recompute b and the distance using c = the last segment index.
    6. If the final computed nearest point on the line is greater than 100 meters away from the stop, there could be a problem with the stop or line geometry, and it is logged for further evaluation. Then set the stop distance to be:
      • 0.0 if the current stop is first
      • the length of the line geometry if the stop is last
      • the previous stop distance otherwise.
  4. Set a equal to b and continue with the next stop.

Before and After Stops

A stop is considered to be before (after) a RouteStopPattern line geometry if its point satisfies one of two conditions:

  1. It is found on the opposite side of the line that is perpendicular to the first (last) line segment and that passes through the first (last) endpoint of the segment.
  2. It is greater than 100 meters distant from any point in the line geometry.

For example:

  x |----------->
 | ]  100 m
Not before:
| x   ]  100 m

Query parameters

The main RouteStopPattern API endpoint is It accepts the following query parameters, which may be freely combined.

Query parameter Type Description Example
onestop_id Onestop ID RouteStopPattern. (
traversed_by Onestop ID Route. Accepts multiple route onestop ids separated by commas. belonging to Route Pittsburg/Bay Point - SFIA/Millbrae
stops_visited Onestop ID Stop. Accepts multiple separated by commas. Having stop MacArthur
trips String Derived from trip. Accepts multiple trips ids separated by commas. Having trips
bbox Lon1,Lat1,Lon2,Lat2 RouteStopPatterns within bounding box in the Bay Area

Response format

  "route_stop_patterns": [
      "identifiers": [
        "imported_from_feed_onestop_ids": [
        "imported_from_feed_version_sha1s": [
        "created_or_updated_in_changeset_id": 10,
        "onestop_id": "r-9q9-local-f68455-dcd599",
        "route_onestop_id": "r-9q9-local",
        "stop_pattern": [
        "geometry": {
          "type": "LineString",
          "coordinates": [
        "is_generated": true,
        "is_modified": true,
        "created_at": "2016-02-06T20:05:59.645Z",
        "updated_at": "2016-02-06T20:05:59.645Z",
        "trips": [
        "tags": {
          "shape_id": null
    "meta": {
      "offset": 0,
      "per_page": 50,
      "next": ""