Skip to main content

Map Builder

Introduction

Map Builder is a tool to transform GeoJSON into Protobuf format, which can reconstruct lane connectivity within the intersection and generate traffic light signals.

Functional modules

RoadNet Generation

from mosstool.map.builder import Builder
object = Builder()
  1. Identify in_ways and out_ways of all junctions, and make them into pairs

    • object.classify()
      • For all ways connected to the junction, calculate the angles at which all ways enter and exit the junction. Cluster the in ways and out ways based on these angles. Calculate the clustering error using cosine distance between cluster centers and points in the same category. Select the cluster with the maximum number of clusters within the allowable range of error as the clustering result for the junction, resulting in in_way_groups and out_way_groups.
      • Each group in in_way_groups consists of the ids of the ways in the same direction and the angle of the cluster center where these in_ways are in. Similarly, out_way_groups follows the same structure.
  2. Connect lanes inside the junction

    • object.create_junction_for_n_n(), object.create_junction_for_1_n()

    • Lane connections:

      • Identify roads in the out direction that are in the same orientation as the in direction, considered as main roads, and the rest are considered as left and right ramps.

      • Connect all lanes that connect the incoming road with the main road, with the left and right ramps only connecting with the outermost lanes corresponding to the left and right exits.

    • Marking roads where sidewalks should be generated:

      • Due to each road connecting to more than one junction, sidewalks need to be created and connected after processing all junctions.

      • Construction rules:

        • Filter out roads with high levels that should not have sidewalks. The program possess HAS_WALK_LANES_HIGHWAY as a control variable.
          • Classify all ways at the junction based on the angle towards the center of the intersection, the result is stored as walk_group in the format [[]angle,[]in_way_ids,[]out_way_ids,], and arrange walk_group counterclockwise.
          • For each group in walk_group, select the rightmost road in the in_way_ids along the forward direction as the in_way and the rightmost road in the out_way_ids along the forward direction as the out_way. If both in_way and out_way exist, mark in_way and out_way to construct the sidewalk on the right side; otherwise, mark in_way/out_way to construct sidewalks on the left and right sides. Store the left and right sidewalks as a pair in walk_pair.
          • In each group of walk_group, at most one road in the in_way_ids is marked for sidewalk construction, and the others are marked not to build sidewalks, with out_way_ids following the same rule. Only one road is chosen because if a road has a ramp in the same direction, only the ramp should have a sidewalk.
  3. Generate walking lanes

    • object._create_walking_lanes()
    • check all walk pairs. If a pedestrian walkway stored in it is marked as not able to be generated, it should be set to None. After filtering out, because adjacent incomplete pairs may be able to be merged into new pairs, further merging processing needs to be done for all pairs.
    • Process to obtain filter_walk_pairs, each pair includes the right-side out walk lanes and left-side in walk lanes (at least one of them is not empty). The in-out connection within the pair results in crosswalks; the in-out connection between the pair and the left-shifted pair results in sidewalks.
  4. Create lanes for roads that are not connected to any junctions

    • object._expand_remain_roads()

Match AOIs to RoadNet

  1. Preprocess input AOIs and POIs

    1. Merge the small AOIs that are contained into the large AOI.

      • Judged by the ratio of the intersection area to the AOI's own area exceeding the threshold COVER_GATE.
    2. Connect small and neighboring AOIs

      • Judged by the area of AOI and SMALL_GATE

      • The goal of this step is to connect separate AOIs with a close relationship, such as clusters of small houses, into a residential area.

    3. Match POI to the AOI that contains it within the geographic range.

      • any POI not contained by any AOI becomes a single point AOI.
    4. Merge adjacent point AOIs into a large polygon AOI

      • If any lane crosses the geometric shape of merged AOI, divide the geometric shape along the road network, with each resulting division being treated as a new AOI to ensure merging does not cross any lanes.
    5. Merge overlapping AOIs and remove the overlapping parts between AOIs.

  2. Match lane to AOI

    1. If a lane is matched to the AOI,
      • the point on the AOI closest to the lane is projected onto the lane as the matching result.
    2. If no lane is matched to the AOI,
      • this indicates that the AOI may be at the center of a road grid. In this case, the matching distance threshold is relaxed to match no more than the number of lanes that do not exceed the number of gates on the AOI.

Post Process

  1. Add overlaps

    • add_junc_lane_overlaps()
      • For all lanes within a junction, if there is spatial overlap, an overlap is added. Each overlap contains the id of the lane itself and the overlapped lane, along with a boolean value indicating whether the lane itself has priority.
      • Criteria for determining overlap priority:
        • Walking lanes have the highest priority.
        • Right-turn lanes have priority when all lanes are straight.
        • Straight lanes have priority over non-straight lanes.
        • Left-turn lanes have priority over right-turn lanes on the opposite side.
  2. Generate driving lane groups for junctions

    • add_driving_lane_group()
      • Get the driving lane group based on the predecessor and successor lanes of the junction that belong to the same road, only processing the driving lanes.
  3. Generate traffic-light

    • Phases for max-pressure algorithm

      • Divide into four groups based on the lane direction angles

        # 0: -pi/4 ~ pi/4
        # 1: pi/4 ~ 3pi/4
        # 2: 3pi/4 ~ 5pi/4
        # 3: 5pi/4 ~ 7pi/4
      • Group 0 and Group 2 are opposing groups in the 0-180 degree range, while Group 1 and Group 3 are opposing groups in the 90-270 degree range.

      • For the two object groups, categorize them into two situations based on the presence of independent left turns within the group:

        • If there are independent left turns within the group, consider opposing through movements and opposing left turns.
        • If there are no independent left turns within the group, do not consider opposing through movements or opposing left turns, only consider clearing the current direction.
    • Fixed program

      • Add pedestrian clearance phase, yellow light phase, and all-red phase transition phases in between all generated phases, and phase time can be specified.