Skip to content

Commit

Permalink
Safely fit polygon to the bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Dec 23, 2024
1 parent 81c76be commit 66a295d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions maps4fs/generator/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit 66a295d

Please sign in to comment.