diff --git a/maps4fs/generator/component.py b/maps4fs/generator/component.py index f93f3ce..d6c649b 100644 --- a/maps4fs/generator/component.py +++ b/maps4fs/generator/component.py @@ -371,8 +371,11 @@ def fit_polygon_into_bounds( bounds = box(min_x, min_y, max_x, max_y) # Intersect the polygon with the bounds to fit it within the map - fitted_polygon = polygon.intersection(bounds) - self.logger.debug("Fitted the polygon into the bounds: %s", bounds) + try: + fitted_polygon = polygon.intersection(bounds) + self.logger.debug("Fitted the polygon into the bounds: %s", bounds) + except Exception as e: + raise ValueError(f"Could not fit the polygon into the bounds: {e}") if not isinstance(fitted_polygon, Polygon): raise ValueError("The fitted polygon is not a valid polygon.")