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()
-
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 thejunction
. 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 inin_way_groups
andout_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.
- For all ways connected to the
- object.classify()
-
Connect
lanes
inside thejunction
-
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 possessHAS_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 inwalk_pair
. - In each group of
walk_group
, at most one road in thein_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.
- 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
- Filter out
-
-
-
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 toNone
. 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-sideout walk lanes
and left-sidein 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.
-
Create
lanes
forroads
that are not connected to anyjunctions
- object._expand_remain_roads()
Match AOIs to RoadNet
-
Preprocess input
AOIs
andPOIs
-
Merge the small
AOIs
that are contained into the largeAOI
.- Judged by the ratio of the intersection area to the AOI's own area exceeding the threshold
COVER_GATE
.
- Judged by the ratio of the intersection area to the AOI's own area exceeding the threshold
-
Connect small and neighboring
AOIs
-
Judged by the area of
AOI
andSMALL_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.
-
-
Match
POI
to theAOI
that contains it within the geographic range.- any
POI
not contained by anyAOI
becomes a single pointAOI
.
- any
-
Merge adjacent point
AOIs
into a large polygonAOI
- If any
lane
crosses the geometric shape of mergedAOI
, divide the geometric shape along the road network, with each resulting division being treated as a newAOI
to ensure merging does not cross anylanes
.
- If any
-
Merge overlapping
AOIs
and remove the overlapping parts betweenAOIs
.
-
-
Match
lane
toAOI
- If a lane is matched to the AOI,
- the point on the
AOI
closest to thelane
is projected onto thelane
as the matching result.
- the point on the
- If no
lane
is matched to theAOI
,- 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 oflanes
that do not exceed the number of gates on theAOI
.
- this indicates that the
- If a lane is matched to the AOI,
Post Process
-
Add overlaps
- add_junc_lane_overlaps()
- For all
lanes
within ajunction
, if there is spatial overlap, an overlap is added. Each overlap contains the id of thelane
itself and the overlappedlane
, along with a boolean value indicating whether thelane
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.
- For all
- add_junc_lane_overlaps()
-
Generate driving lane groups for
junctions
- add_driving_lane_group()
- Get the driving lane group based on the
predecessor
andsuccessor
lanes
of thejunction
that belong to the sameroad
, only processing the drivinglanes
.
- Get the driving lane group based on the
- add_driving_lane_group()
-
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.
-