Skip to content

Commit

Permalink
fix bug in subway lane construction
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchenplus committed Oct 29, 2024
1 parent c4f6cbb commit ab5f7b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
42 changes: 27 additions & 15 deletions mosstool/map/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3837,7 +3837,8 @@ def _add_public_transport(self) -> Set[int]:
if self.public_transport is None:
return set()
logging.info("Adding public transport to map")
public_road_uids = set()
public_road_uids: Set[int] = set()
connected_subway_lane_pairs: Set[Tuple[LineString, LineString]] = set()
projector = self.projector
assert (
projector is not None
Expand All @@ -3860,7 +3861,7 @@ def create_subway_connections(geos: list, stas: list) -> List[List[int]]:
if coords.shape[1] > 2
else np.zeros((coords.shape[0], 1), dtype=np.float64)
)
if any(z == 0 for z in coords_z):
if all(z == 0 for z in coords_z):
coords_z += SUBWAY_HEIGHT_OFFSET
coords_xy = np.stack(projector(*coords.T[:2]), axis=1) # (N, 2)
coords_xyz = np.column_stack([coords_xy, coords_z]) # (N, 3)
Expand All @@ -3874,16 +3875,12 @@ def create_subway_connections(geos: list, stas: list) -> List[List[int]]:
)
lane = cast(LineString, lane)
lane = offset_lane(lane, -0.495 * lane_width)
# Public section routes will not be added to lanes repeatedly.
if lane in self.lane2data:
station_connection_road_ids.append(
{
"road_ids": [self.lane2data[lane]["parent_id"]],
}
)
continue
cur_matcher = {
"id": self.lane_uid,
"id": (
self.lane_uid
if lane not in self.lane2data
else self.lane2data[lane]["uid"]
),
"geo": lane,
# midpoint of polyline
"point": lane.interpolate(0.5, normalized=True).coords[:][0],
Expand All @@ -3892,6 +3889,14 @@ def create_subway_connections(geos: list, stas: list) -> List[List[int]]:
pre_sta_lane_matcher.append(cur_matcher)
cur_sta_lane_matcher.append(cur_matcher)
new_lanes.append(lane)
# Public section routes will not be added to lanes repeatedly.
if lane in self.lane2data:
station_connection_road_ids.append(
{
"road_ids": [self.lane2data[lane]["parent_id"]],
}
)
continue
# Add new lane
self.map_lanes[self.lane_uid] = lane
# Add the connection relationship of the new lane
Expand Down Expand Up @@ -3924,17 +3929,24 @@ def create_subway_connections(geos: list, stas: list) -> List[List[int]]:
self.lane_uid += 1
self.road_uid += 1
next_way_id += 1
for i in range(len(new_lanes) - 1):
cur_sta_geo = stas[i + 1]["geo"]
for cur_sta, cur_lane, next_lane in zip(
stas[1:], new_lanes[:-1], new_lanes[1:]
):
cur_sta_geo = cur_sta["geo"]
z_center = (
np.mean([c[2] for c in cur_sta_geo])
if all(len(c) > 2 for c in cur_sta_geo)
else 0
)
_lane_pair = (cur_lane, next_lane)
if _lane_pair in connected_subway_lane_pairs:
continue
else:
connected_subway_lane_pairs.add(_lane_pair)
self.map_junctions[next_junc_id] = {
"lanes": self._connect_lane_group(
in_lanes=new_lanes[i : i + 1],
out_lanes=new_lanes[i + 1 : i + 2],
in_lanes=[cur_lane],
out_lanes=[next_lane],
lane_turn=mapv2.LANE_TURN_STRAIGHT,
lane_type=mapv2.LANE_TYPE_RAIL_TRANSIT,
junc_id=self.junc_uid,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mosstool"
version = "1.0.15"
version = "1.0.16"
description = "MObility Simulation System toolbox "
authors = ["Jun Zhang <zhangjun990222@qq.com>","Junbo Yan <yanjb20thu@gmali.com>"]
license = "MIT"
Expand Down

0 comments on commit ab5f7b8

Please sign in to comment.