iduedu.PbfSource

class iduedu.PbfSource(path)[source]

A local OpenStreetMap .osm.pbf file answering the queries IduEdu otherwise sends to Overpass.

For a city, pass a compact per-city file cut with iduedu.osm_pbf.split_by_polygons(); reading a whole country extract works too, but the first query then scans the whole file. Later queries on the same source read only the blocks of the file they need.

Parameters:

path (str | PathLike) – The .osm.pbf file.

Raises:

Methods

boundary

The relation osm_id as relation(<osm_id>); out geom; returns it (empty list when absent).

member_elements

out center elements of the given members (dicts with type and ref), sorted by type and id.

member_tags

Tags and coordinates of members, keyed by (type, id), as fetch_member_tags returns them.

routes_by_poly

Public-transport route elements in a polygon, shaped as get_routes_by_poly returns them.

snapshot_time

The replication timestamp from the file header, see snapshot_time().

ways_by_filter

Ways matching an Overpass tag filter inside a polygon.

ways_table

The ways of ways_by_filter() as a table, without the per-point dictionaries.

snapshot_time()[source]

The replication timestamp from the file header, see snapshot_time().

Return type:

datetime | None

ways_by_filter(polygon, way_filter)[source]

Ways matching an Overpass tag filter inside a polygon.

Equivalent to way<way_filter>(poly:"..."); out geom;. Returns Overpass out geom way elements {"type": "way", "id", "bounds", "nodes", "geometry": [{"lat", "lon"}], "tags"}.

Return type:

list[dict]

Parameters:
ways_table(polygon, way_filter)[source]

The ways of ways_by_filter() as a table, without the per-point dictionaries.

Columns type ("way"), id, nodes (list of node ids), geometry ((k, 2) array of lon/lat) and tags. The street builders read this; it holds the same data as the Overpass elements.

Return type:

DataFrame

Parameters:
routes_by_poly(polygon, public_transport_types)[source]

Public-transport route elements in a polygon, shaped as get_routes_by_poly returns them.

Reproduces, statement by statement and in the same order, the Overpass query of iduedu.overpass.downloaders.get_routes_by_poly(): tags of the member ways and then of the member nodes of ground routes (out tags), the ground route relations (out geom) and their route_master relations (out body) and, for subway, the relations sharing a node with a subway route (out geom), their stop-area groups (out body), the stations among their members (out tags), the route masters of the subway routes (out body), the stop_area_members section marker and all their members (out center).

One difference in shape: a way member of a ground route relation carries its geometry as a read-only (k, 2) lon/lat array, shared by all the routes along the way, not as a list of {"lat", "lon"} dicts; the route parser reads both.

Return type:

list[dict]

Parameters:
member_elements(members)[source]

out center elements of the given members (dicts with type and ref), sorted by type and id.

Return type:

list[dict]

Parameters:

members (Iterable[Mapping])

member_tags(members)[source]

Tags and coordinates of members, keyed by (type, id), as fetch_member_tags returns them.

Return type:

dict

Parameters:

members (Iterable[Mapping])

boundary(osm_id)[source]

The relation osm_id as relation(<osm_id>); out geom; returns it (empty list when absent).

Return type:

list[dict]

Parameters:

osm_id (int)