|
1 | 1 | import logging |
2 | 2 | from dataclasses import dataclass |
3 | 3 | from omega_prime.map import Map, Lane, LaneBoundary |
4 | | -from shapely import LineString, Polygon, simplify |
| 4 | +from shapely import LineString, Polygon, simplify, make_valid |
5 | 5 | import numpy as np |
6 | 6 | from betterosi import LaneClassificationType, LaneClassificationSubtype, LaneBoundaryClassificationType |
7 | 7 | from pyxodr_omega_prime.road_objects.network import RoadNetwork as PyxodrRoadNetwork |
|
17 | 17 | from collections import namedtuple |
18 | 18 | import warnings |
19 | 19 |
|
20 | | - |
21 | 20 | logger = logging.getLogger(__name__) |
22 | 21 |
|
23 | 22 |
|
@@ -352,19 +351,17 @@ def create( |
352 | 351 | lane_idx: int = None, |
353 | 352 | ): |
354 | 353 | if side == "left": |
355 | | - if len(boundary.boundary_line) == 1: |
356 | | - polyline = LineString([boundary.boundary_line[0]] * 2) |
357 | | - else: |
358 | | - polyline = LineString(boundary.boundary_line) |
| 354 | + bl = boundary.boundary_line |
359 | 355 | elif side == "right": |
360 | | - if len(boundary.lane_reference_line) == 1: |
361 | | - polyline = LineString([boundary.lane_reference_line[0]] * 2) |
362 | | - else: |
363 | | - polyline = LineString(boundary.lane_reference_line) |
364 | | - |
| 356 | + bl = boundary.lane_reference_line |
365 | 357 | else: |
366 | 358 | raise ValueError(f"Invalid side '{side}'. Expected 'left' or 'right'.") |
367 | 359 |
|
| 360 | + if len(bl) == 1: |
| 361 | + polyline = LineString([bl[0]] * 2) |
| 362 | + else: |
| 363 | + polyline = LineString(bl) |
| 364 | + |
368 | 365 | if type is None and hasattr(boundary, "lane_xml"): |
369 | 366 | type = cls._extract_lane_boundary_type_from_xml(boundary, side) |
370 | 367 |
|
@@ -406,13 +403,16 @@ def create(cls, lane: PyxodrLane, road: PyxodrRoad, lane_section_id: int, lane_i |
406 | 403 | if centre_line is None or not len(centre_line): |
407 | 404 | raise ValueError(f"Lane {lane.id} has no centre_line") |
408 | 405 |
|
409 | | - centerline_2d = lane.centre_line[:, :2] |
| 406 | + centerline = LineString(centre_line[:, :2]) |
| 407 | + if not centerline.is_valid: |
| 408 | + centerline = make_valid(centerline) |
| 409 | + |
410 | 410 | lane_type, lane_subtype = cls._determine_lane_type_and_subtype(lane, road) |
411 | 411 | idx = XodrLaneId(road.id, lane.id, lane_section_id) |
412 | 412 | return cls( |
413 | 413 | _xodr=lane, |
414 | 414 | idx=idx, |
415 | | - centerline=LineString(centerline_2d), |
| 415 | + centerline=centerline, |
416 | 416 | type=lane_type, |
417 | 417 | subtype=lane_subtype, |
418 | 418 | successor_ids=[ |
|
0 commit comments