iduedu.get_bike_graph

iduedu.get_bike_graph(*, osm_id=None, territory=None, simplify=True, clip_by_territory=False, keep_largest_subgraph=True, bike_speed=250.0, max_lts=None, allow_footways=False, elevation=None, network_type='bike', custom_filter=None, osm_edge_tags=None)[source]

Build a cycling UrbanGraph from OpenStreetMap within a given territory.

The graph holds every way a bicycle may use: streets (except motorways and ways closed to bicycles), cycleways, paths and tracks, and footways and pedestrian streets where cycling is permitted (bicycle=yes, designated or permissive). Every edge gets the kind of cycling infrastructure (cycle_infra: track, lane or mixed) and the level of traffic stress (lts, 1 to 4, see level_of_traffic_stress()).

The graph is directed. One-way streets are one-way for bicycles too, unless the way allows riding against the traffic (oneway:bicycle=no or a cycleway*=opposite* tag). Travel time is the length over bike_speed; with elevation it also depends on the grade.

Parameters:
  • osm_id (int | None) – OSM relation/area ID of the territory boundary. Provide this or territory.

  • territory (Polygon | MultiPolygon | gpd.GeoDataFrame | None) – Boundary geometry in EPSG:4326 or GeoDataFrame.

  • simplify (bool) – If True, merges the segments of the ways into edges that run from junction to junction; segments are merged only when they carry the same tags.

  • clip_by_territory (bool) – If True, clips edges by the exact boundary geometry before graph construction.

  • keep_largest_subgraph (bool) – If True, returns only the largest strongly connected component.

  • bike_speed (float) – Cycling speed on flat ground in meters per minute.

  • max_lts (int | None) – Keep only edges with a level of traffic stress up to this one, for example 2 for the network that most adults are willing to ride.

  • allow_footways (bool) – If True, footways and pedestrian streets are used also without an explicit bicycle permission.

  • elevation (Union[str, PathLike, GeoDataFrame, Callable, None]) – Source of heights for add_elevation() (a raster path, a GeoDataFrame of points or contours, or a function). When given, edges get grades, and travel times are rescaled with the cycling speed model of apply_grade_speed().

  • network_type (Literal['bike', 'custom']) – "bike", or "custom" together with custom_filter.

  • custom_filter (str | None) – Custom Overpass way filter used in custom mode.

  • osm_edge_tags (list[str] | None) – Which OSM tags to retain on edges. Overrides config.bike_useful_edges_attr (highway, name, lanes, maxspeed, surface). bridge and tunnel are always kept. The cycleway*, bicycle, oneway and oneway:bicycle tags are always read, and with simplify a change of any of them, or of a kept tag, starts a new edge.

Returns:

Directed multigraph of the cycling network. Edges include geometry in the local CRS, length_meter, time_min, oneway, cycle_infra, lts, the selected OSM tags and, with elevation, grade, grade_max, ascent and descent.

Return type:

UrbanGraph

Raises:

ValueError – If max_lts is not between 1 and 4, or the network type is unknown.