|
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 |
5 | | -from shapely.plotting import plot_polygon |
| 4 | +from shapely import LineString, Polygon, simplify, MultiPolygon |
| 5 | +from matplotlib.patches import Polygon as PltPolygon |
6 | 6 | import numpy as np |
7 | 7 | import matplotlib.pyplot as plt |
8 | 8 | from betterosi import LaneClassificationType, LaneClassificationSubtype, LaneBoundaryClassificationType |
|
17 | 17 | import betterosi |
18 | 18 | from betterosi import MapAsamOpenDrive |
19 | 19 | from collections import namedtuple |
| 20 | +import warnings |
20 | 21 |
|
21 | 22 |
|
22 | 23 | logger = logging.getLogger(__name__) |
@@ -476,15 +477,20 @@ def set_polygon(self): |
476 | 477 | if not polygon.is_valid: |
477 | 478 | raise ValueError(f"Could not compute valid polygon for Lane {self.xodr_idx}") |
478 | 479 | else: |
479 | | - # warnings.warn(f"Needed to simplify and buffer polygon for Lane {self.xodr_idx}.") |
| 480 | + warnings.warn(f"Needed to simplify and buffer polygon for Lane {self.xodr_idx}.") |
480 | 481 | pass |
481 | 482 | else: |
482 | | - # warnings.warn(f"Needed to simplify polygon for Lane {self.xodr_idx}.") |
| 483 | + warnings.warn(f"Needed to simplify polygon for Lane {self.xodr_idx}.") |
483 | 484 | pass |
484 | 485 | self.polygon = polygon |
485 | 486 | return self |
486 | 487 |
|
487 | 488 | def plot(self, ax: plt.Axes): |
488 | 489 | c = "green" if self.type != LaneClassificationType.TYPE_INTERSECTION else "black" |
489 | 490 | ax.plot(*np.asarray(self.centerline).T, color=c, alpha=0.5) |
490 | | - plot_polygon(self.polygon, ax=ax, facecolor="blue", edgecolor="green", alpha=0.2) |
| 491 | + if isinstance(self.polygon, MultiPolygon): |
| 492 | + ps = self.polygon.geoms |
| 493 | + else: |
| 494 | + ps = [self.polygon] |
| 495 | + for p in ps: |
| 496 | + ax.add_patch(PltPolygon(p.exterior.coords, fc="blue", alpha=0.2, ec="black")) |
0 commit comments