mosstool.map.osm.roadnet

Module Contents

Classes

RoadNet

Process OSM raw data to road and junction as geojson formats

Data

API

mosstool.map.osm.roadnet.__all__

[‘RoadNet’]

class mosstool.map.osm.roadnet.RoadNet(proj_str: Optional[str] = None, max_longitude: Optional[float] = None, min_longitude: Optional[float] = None, max_latitude: Optional[float] = None, min_latitude: Optional[float] = None, wikipedia_name: Optional[str] = None, proxies: Optional[dict[str, str]] = None, way_filter: Optional[list[str]] = None)

Process OSM raw data to road and junction as geojson formats

Initialization

Args:

  • proj_str (Optional[str]): projection string, e.g. ‘epsg:3857’

  • max_longitude (Optional[float]): max longitude

  • min_longitude (Optional[float]): min longitude

  • max_latitude (Optional[float]): max latitude

  • min_latitude (Optional[float]): min latitude

  • wikipedia_name (Optional[str]): wikipedia name of the area in OSM.

  • proxies (Optional[dict[str, str]]): proxies for requests, e.g. {‘http’: ‘http://localhost:1080’, ‘https’: ‘http://localhost:1080’}

  • way_filter (Optional[list[str]]): filter for ways when quering OSM

property default_way_settings
_download_osm()

Fetch raw data from OpenStreetMap

_way_length(way)
_way_coords_xy(way)
_way_coords_lonlat(way)
_update_node_ways()

Build node_ways(node_id -> list[way_id]) from ways

_assert_ways()
dump_as_geojson(path: str)
to_topo()

Returns the road topology in the form of a FeatureCollection, where: way: LineString representation, including attributes: id, lanes, highway, max_speed, name junction: MultiPoint representation, including attributes: id, in_ways, out_ways

_get_osm(osm_data_cache: Optional[list[dict]] = None)
_remove_redundant_ways()

Some nodes are connected by multiple paths, remove these redundant paths;

_remove_invalid_ways()

Some ways has non-shapely coordinates; remove them

_remove_simple_joints()

Some joints have only two roads connected, then merge the two roads into the same one (merge the short one into the long one)

_init_junctions()

Initialize junction so that every node connected to more than 1 way is a junction.

_make_all_one_way()

In OSM, single-lane and double-lane roads are mixed and need to be unified into single-lane roads. Originally a two-way road, it became two one-way roads, with a U-turn added at the end of the road.

_remove_out_of_roadnet()

Remove isolated roads outside the main road network, that is, only retain the largest connected component

_merge_junction_by_motif()

Identify fixed patterns in the topology and combine them into a junction

_clean_topo()

If there are multiple roads connecting two intersections, only the one with the largest number of lanes and the shortest length is retained. If there are only two roads at the intersection, one in and one out, then delete the intersection and join the two roads.

create_road_net(output_path: Optional[str] = None, osm_data_cache: Optional[list[dict]] = None, osm_cache_check: bool = False)

Create Road net from OpenStreetMap.

Args:

  • osm_data_cache (Optional[list[dict]]): OSM data cache.

  • output_path (Optional[str]): GeoJSON file output path.

  • osm_cache_check (bool): check the format of input OSM data cache.

Returns:

  • roads and junctions in GeoJSON format.