transitio.infer_shapes#
- transitio.infer_shapes(path, output, pbf, *, strictness='strict', modes=None, check=True)#
Write
path’s feed tooutputwith 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.txtis written andtrips.txt/stop_times.txtgain the references to it.pbf (str or pathlib.Path) – An OSM
.osm.pbfextract covering the feed’s area, as fetched bytransitio.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.ShapeInferenceErrorwhen the written feed carries error-severity notices the input did not. The file is still written, likeInvalidFeedError.
- Returns:
{"level": ..., "written": n, "patterns": n, "by_mode": {...}, "shapes": [...], "skipped": [...]}. Eachshapesentry names itsshape_id, themethodthat produced it (osm_relationormap_matched), the OSM relation id where one was matched, the matchscore, and thetripsit serves; eachskippedentry names the pattern and the stage that refused it. Feeds already carrying a shape for a pattern keep it, recorded asmethod: "existing".A
<output>.provenance.jsonsidecar 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
strictnessor a mode name is unknown, oroutputis one of the inputs.transitio.exceptions.ShapeInferenceError – If
checkand the written feed validates worse than the input did.OSError – If the feed or extract cannot be read, or the output written.