transitio.infer_shapes

Contents

transitio.infer_shapes#

transitio.infer_shapes(path, output, pbf, *, strictness='strict', modes=None, check=True)#

Write path’s feed to output with inferred shapes.

Parameters:
  • path (str or pathlib.Path) – Source GTFS .zip.

  • output (str or pathlib.Path) – Destination for the written feed (overwritten). Every table of the source feed is carried over; shapes.txt is written and trips.txt/stop_times.txt gain the references to it.

  • pbf (str or pathlib.Path) – An OSM .osm.pbf extract covering the feed’s area, as fetched by transitio.fetch_pbf().

  • strictness (str or Level, default "strict") – "strict", "relaxed", "permissive", or a Level. Higher tolerance infers more shapes and more wrong ones; the report records what each shape rests on.

  • modes (iterable of str, optional) – Mode families to infer for (bus, trolleybus, tram, subway, train, ferry). Defaults to every mode the feed carries. Unknown names raise.

  • check (bool, default True) – Raise transitio.exceptions.ShapeInferenceError when the written feed carries error-severity notices the input did not. The file is still written, like InvalidFeedError.

Returns:

{"level": ..., "written": n, "patterns": n, "by_mode": {...}, "shapes": [...], "skipped": [...]}. Each shapes entry names its shape_id, the method that produced it (osm_relation or map_matched), the OSM relation id where one was matched, the match score, and the trips it serves; each skipped entry names the pattern and the stage that refused it. Feeds already carrying a shape for a pattern keep it, recorded as method: "existing".

A <output>.provenance.json sidecar records the same report alongside the feed, so an inferred alignment stays distinguishable from an operator-published one after the fact — the strictness a shape rests on is not recoverable from GTFS itself.

Return type:

dict

Raises:
  • ValueError – If strictness or a mode name is unknown, or output is one of the inputs.

  • transitio.exceptions.ShapeInferenceError – If check and the written feed validates worse than the input did.

  • OSError – If the feed or extract cannot be read, or the output written.