Route-Route Matching

This section explains how ATLAS routes are linked to OSM routes via the RouteState module.

Important distinction:

  • 2.4 Stop-stop matching using routes is stop-level matching (ATLAS stop <-> OSM stop).
  • This section is route-level linking (ATLAS route <-> OSM route), which pre-computes route equivalency and later writes to routes_matched.

Where It Happens In The Pipeline

Route-route matching runs during route import preparation, after stop matching has already produced the set of importable ATLAS SLOIDs.

flowchart LR A[Load entity-first route CSVs] --> B[Initialize RouteState] B --> C[Filter route_atlas_stops to importable SLOIDs] C --> D[Compute Route Equivalencies] D --> E[Build route write payload] E --> F[import_to_database] F --> G[Bulk write routes_matched]

Concretely, matching_and_import_db/database/route_loader.py loads the entity-first route CSVs, filters atlas_route_stops.csv to the SLOIDs that will actually be imported, and then calls RouteState.load_and_match() to populate the route equivalency map. That map is immediately materialized into routes_matched rows for importer.py.

Inputs

The broader route import path depends on the entity-first route metadata:

  • atlas_routes.csv, atlas_route_directions.csv, and atlas_route_stops.csv
  • osm_routes.csv, osm_route_tags.csv, and osm_route_members.csv

The route equivalency lookup itself only needs atlas_routes.csv and osm_routes.csv.

Matching Rules

The linker applies the following route-pair rules for each OSM route (relation):

  1. Exact key match first

    • If the OSM gtfs_route_id exists in the ATLAS routes, link directly.
  2. Normalized route-id fallback

    • If no exact key match exists, normalize the OSM route id with normalize_route_id().
    • Normalization rule: replace -jNN with -jXX (for example 11-T-j25-1 -> 11-T-jXX-1).
    • Match the normalized route id against ATLAS normalized route IDs.
  3. Unique pair write guard

    • The mapping creates an $O(1)$ lookup dictionary osm_route_to_atlas_route.
    • At most one ATLAS route ID is mapped to any OSM route relation.

Resolution Flow

flowchart TD O[OSM route relation] --> E{Exact key exists in ATLAS map?} E -->|Yes| M1[Map OSM relation to ATLAS Route] E -->|No| N[Normalize OSM route_id -jNN to -jXX] N --> F{Normalized key exists in ATLAS map?} F -->|Yes| M2[Map OSM relation to ATLAS Route] F -->|No| X[No route pair link]

What This Step Does Not Do

  • It does not run spatial distance checks.
  • It does not run fuzzy text similarity matching.
  • It does not consume stop predicate scores.

Its responsibility is deterministic route-id linking using prepared route tables. Direction rows and stop-membership rows are loaded alongside that mapping for route import, but they are not part of the RouteState equivalency decision.

Output Tables Affected

  • route_osm_stops: ordered OSM route membership rows.
  • route_atlas_stops: ordered ATLAS route membership rows.
  • routes_matched: route-route links between ATLAS and OSM.

Related Documentation

Data update running in background
Preparing update... | Phase: initializing
Data update in progress
Core data is being refreshed. Use this time to read the documentation.
Elapsed: -- ETA: -- Phase: idle