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, shared_paths='local')#

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

Parameters:
  • network_type (str) –

    What kind of network to parse. Possible values are:

    • ’walking’ (OSMnx ‘walk’)

    • ’cycling’ (OSMnx ‘bike’)

    • ’driving’ (OSMnx ‘drive’)

    • ’driving+service’ (OSMnx ‘drive_service’)

    • ’all’

    • ’all_public’.

    The filters follow the way filters of OSMnx closely and in most cases select the same ways. Where the two differ, pyrosm follows OSM’s access rules: a way tagged access=no is left out unless a tag of the network’s mode of transport, such as foot=yes, allows the use. The OSMnx name of a network type is accepted as well.

    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, so {‘waterway’: [‘river’]} finds no rivers; a dict without a highway key that keeps ways gives a warning that shows the same filter in the bracket form, when it can be written in that form;

    • 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).

    The regex dict and the bracket strings select ways by the filter’s own keys, so they also build networks of other ways than streets, e.g. ‘[“waterway”=”river”]’ or ‘[“railway”=”tram”]’.

  • 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’, as in every other reader and for every form of the filter (a plain dict, a regex or a bracket 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”.

  • shared_paths (str (default: 'local')) –

    Which ways built for the other mode the ‘walking’ and ‘cycling’ networks keep when the way has no tag of the network’s mode: a cycle way without a foot tag in the walking network, a foot way without a bicycle tag in the cycling network.

    • ’tagged’: none of them, OSM’s worldwide default.

    • ’local’: those that the way’s country lets the mode use (in Finland, pedestrians may use cycle ways; in Norway, cyclists may also use foot ways).

    • ’all’: all of them, also where the country’s rules do not allow the mode on them.

    A tag of the mode decides at every level as on any other way: foot=no leaves a cycle way out of the walking network and bicycle=yes keeps a foot way in the cycling network. foot=use_sidepath, which sends pedestrians to a sidewalk mapped beside the way, leaves the way out of the walking network with ‘tagged’ and ‘local’ and not with ‘all’; the cycling network keeps a way tagged bicycle=use_sidepath. ‘tagged’ and ‘all’ apply only to the walking and cycling networks without a custom_filter.

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