diff --git a/lib/cartopy/crs.py b/lib/cartopy/crs.py index f1ae00cbeb..525c156562 100644 --- a/lib/cartopy/crs.py +++ b/lib/cartopy/crs.py @@ -401,7 +401,7 @@ def transform_points(self, src_crs, x, y, z=None, trap=False): self.is_geodetic()): # convert from [0,360] to [-180,180] x = np.array(x, copy=True) - to_180 = x > 180 + to_180 = (x > 180) | (x < -180) x[to_180] = (((x[to_180] + 180) % 360) - 180) try: result[:, 0], result[:, 1], result[:, 2] = \ diff --git a/lib/cartopy/tests/test_crs.py b/lib/cartopy/tests/test_crs.py index 43384ccd70..88649772f7 100644 --- a/lib/cartopy/tests/test_crs.py +++ b/lib/cartopy/tests/test_crs.py @@ -173,6 +173,17 @@ def test_transform_points_xyz(self): assert_arr_almost_eq(glon, soly) assert_arr_almost_eq(galt, solz) + def test_transform_points_180(self): + # Test that values less than -180 and more than 180 + # get mapped to the -180, 180 interval + x = np.array([-190, 190]) + y = np.array([0, 0]) + + proj = ccrs.PlateCarree() + + res = proj.transform_points(x=x, y=y, src_crs=proj) + assert_array_equal(res[..., :2], [[170, 0], [-170, 0]]) + def test_globe(self): # Ensure the globe affects output. rugby_globe = ccrs.Globe(semimajor_axis=9000000, diff --git a/lib/cartopy/trace.pyx b/lib/cartopy/trace.pyx index 82ea1a4316..2942d14c7a 100644 --- a/lib/cartopy/trace.pyx +++ b/lib/cartopy/trace.pyx @@ -231,7 +231,7 @@ cdef class Interpolator: else: raise - if self.to_180 and xx > 180 and xx != HUGE_VAL: + if self.to_180 and (xx > 180 or xx < -180) and xx != HUGE_VAL: xx = (((xx + 180) % 360) - 180) dest_xy.x = xx * self.dest_scale