pyrosm.OSM.get_network

pyrosm.OSM.get_network#

OSM.get_network(network_type='walking', extra_attributes=None, nodes=False, timestamp=None, custom_filter=None, filter_type=None, tags_to_keep=None)#

Parses street networks from OSM for walking, driving, and cycling.

Parameters:
  • network_type (str) –

    What kind of network to parse. Possible values are:

    • ’walking’

    • ’cycling’

    • ’driving’

    • ’driving+service’

    • ’all’.

    When custom_filter is given, network_type no longer selects the ways to keep; it only determines the graph semantics used by OSM.to_graph (directionality / connectivity), e.g. pass network_type=’driving’ for a directed custom network or keep the default ‘walking’ for a bidirectional one.

  • extra_attributes (list (optional)) – Additional OSM tag keys that will be converted into columns in the resulting GeoDataFrame.

  • tags_to_keep (list (optional)) – When given, only these OSM tag keys are kept as columns, replacing the default set of tag columns (reduces memory). Structural columns and filtering are unaffected; extra_attributes still apply.

  • nodes (bool (default: False)) – If True, 1) the nodes associated with the network will be returned in addition to edges, and 2) every segment of a road constituting a way is parsed as a separate row (to enable full connectivity in the graph). Works together with custom_filter so that custom-filtered networks can also be exported to a graph.

  • custom_filter (dict | str | list (optional)) –

    A custom filter for selecting which ways to keep. When given, it replaces the predefined network_type filter (the two are not combined), and the filter keys are added as columns to the result. Three forms are supported:

    • a dict like {‘highway’: [‘footway’, ‘residential’], ‘bicycle’: [‘yes’]} (exact values, combined with OR; only ways having a highway tag are considered);

    • a dict with compiled regex values, e.g. {‘ref’: [re.compile(r’I[ -]?20’)]};

    • an Overpass-style bracket string, or a list of them, e.g. [‘[“highway”~”cycleway”]’, ‘[“highway”~”path”][“bicycle”~”designated”]’] (each string is the AND of its brackets, a list is their OR). These select ways by the filter’s own keys, so non-highway networks (e.g. railway, cycleway) are supported.

  • filter_type (str (optional)) – Whether custom_filter should ‘keep’ or ‘exclude’ the matching ways. Only consulted when custom_filter is given. When omitted it defaults to ‘keep’ for a regex/bracket (advanced) filter and ‘exclude’ for a plain-dict filter; the predefined network_type filters are always applied as ‘exclude’.

  • timestamp (str | datetime | int) –

    If provided, the data from given moment of time will be returned. The time should be provided in UTC. Note: This functionality only works with OSH.PBF files that can be downloaded manually e.g. from Geofabrik (requires login with OSM account).

    The logic: the closest version of each element up to given timestamp will be selected to the result. This means that elements can be older than the given timestamp (the most up-to-date version is selected), but not newer (records having exactly the selected timestamp will be kept). In case only a date is given, the time will represent midnight of the given day, such as “2021-01-01 00:00:00”.

Returns:

  • gdf_edges or (gdf_nodes, gdf_edges)

  • Return type

  • ———–

  • geopandas.GeoDataFrame or tuple

See also

Take a look at the OSM documentation for further details about the data: https://wiki.openstreetmap.org/wiki/Key:highway