diff --git a/pyresample/geometry.py b/pyresample/geometry.py index 0dc69048b..8dbc51c21 100644 --- a/pyresample/geometry.py +++ b/pyresample/geometry.py @@ -2592,14 +2592,8 @@ def get_area_slices(self, area_to_cover, shape_divisible_by=None): "equal.") data_boundary = Boundary(*get_geostationary_bounding_box_in_lonlats(self)) - if area_to_cover.is_geostationary: - area_boundary = Boundary( - *get_geostationary_bounding_box_in_lonlats(area_to_cover)) - else: - area_boundary = AreaDefBoundary(area_to_cover, 100) - - intersection = data_boundary.contour_poly.intersection( - area_boundary.contour_poly) + area_boundary = self._get_area_to_cover_boundary(area_to_cover) + intersection = data_boundary.contour_poly.intersection(area_boundary.contour_poly) if intersection is None: logger.debug('Cannot determine appropriate slicing. ' "Data and projection area do not overlap.") @@ -2619,6 +2613,15 @@ def get_area_slices(self, area_to_cover, shape_divisible_by=None): return (check_slice_orientation(x_slice), check_slice_orientation(y_slice)) + @staticmethod + def _get_area_to_cover_boundary(area_to_cover: AreaDefinition) -> Boundary: + try: + if area_to_cover.is_geostationary: + return Boundary(*get_geostationary_bounding_box_in_lonlats(area_to_cover)) + return AreaDefBoundary(area_to_cover, 100) + except ValueError: + raise NotImplementedError("Can't determine boundary of area to cover") + def crop_around(self, other_area): """Crop this area around `other_area`.""" xslice, yslice = self.get_area_slices(other_area) diff --git a/pyresample/test/test_geometry/test_area.py b/pyresample/test/test_geometry/test_area.py index 0b6d6ef7d..b6b0eb003 100644 --- a/pyresample/test/test_geometry/test_area.py +++ b/pyresample/test/test_geometry/test_area.py @@ -1814,6 +1814,17 @@ def test_on_flipped_geos_area(self, create_test_area): assert slice_lines == expected_slice_lines assert slice_cols == expected_slice_cols + def test_area_to_cover_all_nan_bounds(self, geos_src_area, create_test_area): + """Check area slicing when the target doesn't have a valid boundary.""" + area_def = geos_src_area + # An area that is a subset of the original one + area_to_cover = create_test_area( + {"proj": "moll"}, + 1000, 1000, + area_extent=(-18000000.0, -9000000.0, 18000000.0, 9000000.0)) + with pytest.raises(NotImplementedError): + area_def.get_area_slices(area_to_cover) + class TestBoundary: """Test 'boundary' method for AreaDefinition classes."""