iduedu.merge_gtfs_feeds

iduedu.merge_gtfs_feeds(sources, *, prefixes=None, merge_stops_within=None, deduplicate=False, duplicate_platform_tolerance=0.5, crs=None, validate=True)[source]

Combine several GTFS feeds into one that the graph builder can consume.

Identifiers are qualified by their source, so a route_id of 1 in two feeds becomes two distinct routes. Definitions and references are rewritten together, and blank optional references stay blank.

Parameters:
  • sources (Sequence[str | Path | GTFSFeed]) – Paths to GTFS directories or ZIP archives, or already-read feeds. A single source is returned unchanged unless stop merging is requested, so this function is a no-op where merging is not needed.

  • prefixes (Optional[Sequence[str]]) – One prefix per source. Defaults to each source’s file name, with a numeric suffix where two sources share one.

  • merge_stops_within (float | None) – Distance in metres below which stops published by different feeds are treated as the same place and fused into one node. None (the default) keeps every stop distinct: fusing stops changes the topology of the network, and doing it silently would make an inferred transfer indistinguishable from a published one. Values around 15–25 m suit feeds from different agencies; the 1 m used for OSM platforms is far too tight here, because two agencies survey the same kerb independently.

  • deduplicate (bool) – Count once what several sources publish twice: fuse platforms of different sources within duplicate_platform_tolerance metres and drop trips another source already runs identically. See deduplicate_across_feeds(). Off by default: it changes the feed.

  • duplicate_platform_tolerance (float) – Metres within which two sources’ platforms are treated as one when deduplicate is on.

  • crs (Any | None) – Projected CRS in metres used for the distance test. Estimated from the stops when omitted.

  • validate (bool) – Run iduedu.gtfs.validate_gtfs_feed() on the result. Leave this on: it is what makes the merge verifiable rather than merely plausible.

Return type:

GTFSFeed

Returns:

A iduedu.gtfs.GTFSFeed whose source names the merged inputs.

Raises:
  • ValueError – If no sources are given, or the number of prefixes does not match the number of sources.

  • GTFSValidationError – If the merged feed breaks a GTFS contract.