mosstool.map.builder.builder

Module Contents

Classes

Builder

build map from geojson format files

Data

API

mosstool.map.builder.builder.__all__

[‘Builder’]

class mosstool.map.builder.builder.Builder(net: Union[geojson.FeatureCollection, mosstool.type.Map], proj_str: Optional[str] = None, aois: Optional[geojson.FeatureCollection] = None, pois: Optional[geojson.FeatureCollection] = None, public_transport: Optional[dict[str, list]] = None, pop_tif_path: Optional[str] = None, landuse_shp_path: Optional[str] = None, traffic_light_min_direction_group: int = 3, default_lane_width: float = 3.2, gen_sidewalk_speed_limit: float = 0, gen_sidewalk_length_limit: float = 5.0, expand_roads: bool = False, road_expand_mode: Union[Literal[L], Literal[M], Literal[R]] = 'R', aoi_mode: Union[Literal[append], Literal[overwrite]] = 'overwrite', traffic_light_mode: Union[Literal[green_red], Literal[green_yellow_red], Literal[green_yellow_clear_red]] = 'green_yellow_clear_red', multiprocessing_chunk_size: int = 500, green_time: float = 30.0, yellow_time: float = 5.0, strict_mode: bool = False, merge_aoi: bool = True, correct_green_time: bool = False, split_too_long_walking_lanes: bool = False, max_walking_lane_length: float = 100.0, aoi_matching_distance_threshold: float = 30.0, pt_station_matching_distance_threshold: float = 30.0, pt_station_matching_distance_relaxation_threshold: float = 30.0, output_lane_length_check: bool = False, default_lane_turn_num_dict: dict[str, int] = {'AUXILIARY_SMALL_LEFT': 1, 'AUXILIARY_SMALL_RIGHT': 1, 'AUXILIARY_LARGE_LEFT': 1, 'AUXILIARY_LARGE_RIGHT': 1, 'AUXILIARY_AROUND': 1, 'MAIN_AROUND': 1, 'MAIN_SMALL_LEFT': 1, 'MAIN_LARGE_LEFT': 2, 'MAIN_SMALL_RIGHT': 1, 'MAIN_LARGE_RIGHT': 2}, min_straight_main_lane_ratio: float = 0.5, enable_tqdm: bool = False, workers: int = cpu_count())

build map from geojson format files

Initialization

Args:

  • net (FeatureCollection | Map): road network

  • proj_str (str): projection string, if not provided, all coordinates in input geojson files will be seen as xyz coords.

  • aois (FeatureCollection): area of interest

  • pois (FeatureCollection): point of interest

  • public_transport (dict[str, list]): public transports in json format

  • pop_tif_path (str): path to population tif file

  • landuse_shp_path (str): path to landuse shape file

  • traffic_light_min_direction_group (int): minimum number of lane directions for traffic-light generation

  • default_lane_width (float): default lane width

  • gen_sidewalk_speed_limit (float): speed limit to generate sidewalk

  • gen_sidewalk_length_limit (float): length limit to generate sidewalk

  • expand_roads (bool): expand roads according to junction type

  • road_expand_mode (str): road expand mode

  • aoi_mode (str): aoi appending mode. append takes effect when the input net is Map, incrementally adding the input AOIs; overwrite only adds the input AOIs, ignoring existing ones.

  • traffic_light_mode (str): fixed time traffic-light generation mode. green_red means only green and red light will be generated, green_yellow_red means there will be yellow light between green and red light, green_yellow_clear_red add extra pedestrian clear red light.

  • multiprocessing_chunk_size (int): the maximum size of each multiprocessing chunk

  • green_time (float): green time

  • yellow_time (float): yellow time

  • strict_mode (bool): when enabled, causes the program to exit whenever a warning occurs

  • merge_aoi (bool): merge nearby aois

  • correct_green_time (bool): whether to correct green time, if true, the green time will be corrected to the minimum green time that satisfies one person to walk across the junction.

  • split_too_long_walking_lanes (bool): whether to split too long walking lanes

  • max_walking_lane_length (float): the maximum length of walking lanes, if the length of a walking lane is larger than this value, it will be split into two lanes.

  • aoi_matching_distance_threshold (float): Only AOIs whose distance to the road network is less than this value will be added to the map.

  • pt_station_matching_distance_threshold (float): Only stations whose distance to the road network is less than this value will be added to the map.

  • pt_station_matching_distance_relaxation_threshold (float): The relaxation distance threshold for stations whose distance to road network is larger than pt_station_matching_distance_threshold.

  • output_lane_length_check (bool): when enabled, will do value checks lane lengths in output map.

  • default_lane_turn_num_dict (dict[str,int]): default lane turn number dictionary.

  • min_straight_main_lane_ratio (float): the minimum ratio of straight main lanes to total main lanes.

  • enable_tqdm (bool): when enabled, use tqdm to show the progress bars.

  • workers (int): number of workers

uid_mapping

None

Intersection category: (in_cluster, out_cluster) -> []jid The junctions that have been processed are deleted from here.

_junction_keys

[]

To draw the junction shape, use to store the number of entry and exit roads of the junction

map_roads

None

id -> map road data{[]lane shapely(from left to right), highway, max_speed, name}

map_junctions

None

id -> map junction data{[]lane shapely}

lane2data: dict[shapely.geometry.LineString, dict[str, Any]]

None

lane shapely -> map lane shapely(lane_uid, []in_lane uid, []out_lane uid)

map_lanes

None

id -> map lane data(lane shapely)

no_left_walk

‘set(…)’

There is no way id for the left sidewalk

no_right_walk

‘set(…)’

There is no way id for the right sidewalk

_connect_lane_group(in_lanes: list[shapely.geometry.LineString], out_lanes: list[shapely.geometry.LineString], lane_turn: mosstool.map._map_util.const.mapv2.LaneTurn, lane_type: mosstool.map._map_util.const.mapv2.LaneType, junc_id: int, in_walk_type: typing.Union[typing.Literal[in_way], typing.Literal[out_way], typing.Literal[]] = '', out_walk_type: typing.Union[typing.Literal[in_way], typing.Literal[out_way], typing.Literal[]] = '') list[shapely.geometry.LineString]

Connect two lanes

_delete_lane(lane_id: int, delete_road: bool = False) None

Delete the lane. If it belongs to road, the road will also be deleted. If it belongs to the junction, delete the lane from the junction.

_reset_lane_uids(orig_lane_uids: list[int], new_lane_uids: list[int]) None

Reset lane uid

draw_junction(jid: int, save_path: str, trim_length: float = 50)

Draw the junction as a picture and save it in save_path Draw junction to image and save to save_path

Args:

  • jid (int): junction id

  • save_path (str): path to save image

  • trim_length (float): length of the road to draw

Returns:

  • None

draw_walk_junction(jid: int, save_path: str, trim_length: float = 50)

Draw the junction as a picture and save it in save_path Draw junction to image and save to save_path (for walking lane)

Args:

  • jid (int): junction id

  • save_path (str): path to save image

  • trim_length (float): length of the road to draw

Returns:

  • None

_classify()

Classify roads entering and leaving junctions

  1. First use KMeans for angle clustering

_classify_main_way_ids()

Return the main road and auxiliary road in wids according to in_way_group/out_way_group

_expand_roads(wids: list[int], junc_type, junc_id: int, way_type: typing.Union[typing.Literal[main], typing.Literal[around], typing.Literal[right], typing.Literal[left], typing.Literal[]] = '')

Extension road

  1. Expand the lane of the specified wid

  2. The front and rear inward contraction is proportional to the width of the lane + the distance to the number of roads entering and exiting the junction.

_expand_remain_roads()

Expand the remaining roads

  1. The front and rear shrink inward by a distance equal to the width of the lane (different from the road connected to the junction)

_add_sidewalk(wid, lane: shapely.geometry.LineString, other_lane: shapely.geometry.LineString, walk_type: Union[Literal[left], Literal[right]], walk_lane_end_type: Union[Literal[start], Literal[end]])

Add sidewalk

_create_junction_walk_pairs(in_way_groups: tuple[list[tuple[mosstool.map._map_util.const.np.ndarray, list[int]]]], out_way_groups: tuple[list[tuple[mosstool.map._map_util.const.np.ndarray, list[int]]]], has_main_group_wids: set, junc_center: tuple[float, float])
_create_junction_for_1_n()

For an junction with 1 in and n out, create an junction Basic logic:

  1. Identify the roads in the out direction that are in the same direction as the in direction and regard them as main roads, while the rest are left and right ramps.

  2. All lanes connecting incoming and outgoing main roads

  3. The left and right ramps are only connected to the outermost lane on the corresponding side of the main road.

_create_junction_for_n_n()

Dealing with junctions

_create_walking_lanes()
_add_junc_lane_overlaps()

junc lanesadd overlap

_add_driving_lane_group()

Clustering lane groups from the lanes at the junction

_add_traffic_light()
_add_public_transport() set[int]
_add_reuse_aoi()

Match aoi to road network

_add_input_aoi()

Match aoi to road network

_add_all_aoi()
write2json(topo_path: str, output_path: str)
_post_process()

Map data post-processing

get_output_map(name: str)

Post-processing converts map data into output format

write2db(coll: pymongo.collection.Collection, name: str)
build(name: str)