uxsim.OSMImporter.OSMImporter¶
- class uxsim.OSMImporter.OSMImporter[source]¶
OpenStreetMap importer using OSMnx. Work in progress. Import from OSM is experimental and may not work as expected. It is functional but may produce inappropriate networks for simulation, such as too many nodes, too many deadends, fragmented networks.
- __init__()¶
Methods
__init__
()import_osm_data
([south, east, west, bbox, ...])Import road network data from OpenStreetMap using OSMnx.
osm_network_postprocessing
(links, ...[, ...])Postprocess the network to make it suitable for simulation.
osm_network_to_World
(nodes, links[, ...])Load the imported network to the World object of UXsim.
osm_network_visualize
(links[, figsize, ...])Visualize the imported network.
- import_osm_data(south=None, east=None, west=None, bbox=None, custom_filter='["highway"~"trunk|primary"]', default_number_of_lanes_mortorway=3, default_number_of_lanes_trunk=3, default_number_of_lanes_primary=2, default_number_of_lanes_secondary=2, default_number_of_lanes_residential=1, default_number_of_lanes_tertiary=1, default_number_of_lanes_others=1, default_maxspeed_mortorway=100, default_maxspeed_trunk=60, default_maxspeed_primary=50, default_maxspeed_secondary=50, default_maxspeed_residential=30, default_maxspeed_tertiary=30, default_maxspeed_others=30)[source]¶
Import road network data from OpenStreetMap using OSMnx.
- Parameters:
north (float) – The latitudes and longitudes of the area to be imported.
south (float) – The latitudes and longitudes of the area to be imported.
east (float) – The latitudes and longitudes of the area to be imported.
west (float) – The latitudes and longitudes of the area to be imported.
bbox (list) – The bounding box of the area to be imported. The order is [north, south, east, west]. This is prioritized than north, south, east, west arguments.
custom_filter (str) – The filter to be used for importing the data. The default is ‘[“highway”~”trunk|primary”]’, which means that only trunk and primary roads (usually correspond to major arterial roads) are imported.
default_number_of_lanes_* (int) – The default number of lanes for * {road_type}.
default_maxspeed_* (float) – The default maximum speed for * {road_type}.
- Returns:
links (list) – A list of links, where each element is a list of [name, from, to, lanes, maxspeed].
nodes (dict) – A dictionary of nodes, where the key is the node ID and the value is a list of [node_id, x, y].
- osm_network_postprocessing(links, node_merge_threshold, node_merge_iteration=5, enforce_bidirectional=False)[source]¶
Postprocess the network to make it suitable for simulation. First, it aggregates the network by merging nodes that are closer than the threshold. Second, if enforce_bidirectional is True, it adds reverse links for each link to eliminate deadend nodes as much as possible.
- Parameters:
nodes (list) – A list of nodes, where each element is a list of [node_id, x, y].
links (list) – A list of links, where each element is a list of [name, from, to, lanes, maxspeed].
node_merge_threshold (float) – If two nodes are connected by a link that is shorter than this threshold, the nodes are merged and the link is removed.
node_merge_iteration (int) – The number of iterations for the node merge.
enforce_bidirectional (bool) – True if you want to enforce bidirectional links. It will automatically add a reverse link for each link. This will eliminate deadend nodes as much as possible, but the original network topology is not preserved rigorously.
- Returns:
nodes (list) – A list of nodes, where each element is a list of [node_id, x, y].
links (list) – A list of links, where each element is a list of [name, from, to, lanes, maxspeed].
- osm_network_to_World(nodes, links, default_jam_density=0.2, coef_degree_to_meter=111000)[source]¶
Load the imported network to the World object of UXsim.
- Parameters:
nodes (list) – A list of nodes, where each element is a list of [node_id, x, y].
links (list) – A list of links, where each element is a list of [name, from, to, lanes, maxspeed, length].
default_jam_density (float) – The default jam density for the links.
coef_degree_to_meter (float) – The coefficient to convert lon/lat degree to meter. Default is 111000.