From 832f97bf18dc6febb753590f3fa36930b48530ad Mon Sep 17 00:00:00 2001 From: Vincent Verelst Date: Thu, 23 Apr 2026 15:41:35 +0200 Subject: [PATCH 1/2] remove redundant BBoxDict.as_polygon() method --- openeo/util.py | 15 --------------- tests/test_util.py | 18 ------------------ 2 files changed, 33 deletions(-) diff --git a/openeo/util.py b/openeo/util.py index 854cc17db..fd2517652 100644 --- a/openeo/util.py +++ b/openeo/util.py @@ -588,21 +588,6 @@ def _crs_with_cyclic_x(crs: Union[None, str]) -> bool: """ return normalize_crs(crs) == 4326 - def as_polygon(self) -> shapely.geometry.Polygon: - """ - Get bounding box as a shapely Polygon. - Simple single polygon, but not ideal for proper handling of antimeridian crossing in EPSG:4326, - which require to split the geometry in two parts: use `as_geometry` instead for that. - """ - west, east = self["west"], self["east"] - if self._crs_with_cyclic_x(self.get("crs")): - west, east = self.normalize_west_east_longitude(west=west, east=east) - if east < west: - # TODO: this assumes "cyclic" implies longitude in degrees (EPSG:4326) - east += 360 - - return shapely.geometry.box(minx=west, miny=self["south"], maxx=east, maxy=self["north"]) - def as_geometry(self) -> Union[shapely.geometry.Polygon, shapely.geometry.MultiPolygon]: """Get bounding box as a shapely geometry (Polygon or MultiPolygon when crossing antimeridian)""" west, east = self["west"], self["east"] diff --git a/tests/test_util.py b/tests/test_util.py index 0af7ca278..35b2e3e2c 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -798,24 +798,6 @@ def test_to_bbox_dict_from_geometry(self): geometry = shapely.geometry.Polygon([(4, 2), (7, 4), (5, 8), (3, 3), (4, 2)]) assert to_bbox_dict(geometry) == {"west": 3, "south": 2, "east": 7, "north": 8} - def test_as_polygon(self): - bbox = BBoxDict(west=1, south=2, east=3, north=4) - polygon = bbox.as_polygon() - assert isinstance(polygon, shapely.geometry.Polygon) - assert shapely.geometry.mapping(polygon) == { - "type": "Polygon", - "coordinates": (((3, 2), (3, 4), (1, 4), (1, 2), (3, 2)),), - } - - def test_as_polygon_across_anti_meridian(self): - bbox = BBoxDict(west=170, south=50, east=-170, north=51, crs=4326) - polygon = bbox.as_polygon() - assert isinstance(polygon, shapely.geometry.Polygon) - assert shapely.geometry.mapping(polygon) == { - "type": "Polygon", - "coordinates": (((190, 50), (190, 51), (170, 51), (170, 50), (190, 50)),), - } - def test_as_geometry_basic(self): bbox = BBoxDict(west=1, south=2, east=3, north=4) polygon = bbox.as_geometry() From a30d3bd25337c2df04c66e52f53d9b8ec839e89b Mon Sep 17 00:00:00 2001 From: Vincent Verelst Date: Thu, 23 Apr 2026 15:45:11 +0200 Subject: [PATCH 2/2] change as_polgyon to as_geometry in job splitter --- openeo/extra/job_management/_job_splitting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openeo/extra/job_management/_job_splitting.py b/openeo/extra/job_management/_job_splitting.py index c4fe25cf1..9cc854c17 100644 --- a/openeo/extra/job_management/_job_splitting.py +++ b/openeo/extra/job_management/_job_splitting.py @@ -233,7 +233,7 @@ def _split_bounding_box(to_cover: BBoxDict, tile_size: float) -> List[Polygon]: south=south + row * tile_size, east=min(west + (col + 1) * tile_size, east), north=min(south + (row + 1) * tile_size, north), - ).as_polygon() + ).as_geometry() ) return tiles