diff --git a/lib/mpl_toolkits/basemap/__init__.py b/lib/mpl_toolkits/basemap/__init__.py index e4fdc40a3..3b2859aed 100644 --- a/lib/mpl_toolkits/basemap/__init__.py +++ b/lib/mpl_toolkits/basemap/__init__.py @@ -4228,6 +4228,21 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\ returns a matplotlib.image.AxesImage instance. """ + + + # fix PIL import on some versions of OSX and scipy + try: + from PIL import Image + except ImportError: + try: + import Image + except ImportError: + msg = ('arcgisimage method requires PIL ' + '(http://pillow.readthedocs.io)') + raise ImportError(msg) + + + if not hasattr(self,'epsg'): msg = dedent(""" Basemap instance must be creating using an EPSG code @@ -4247,7 +4262,7 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\ arcgisimage cannot handle images that cross the dateline for cylindrical projections.""") raise ValueError(msg) - if self.projection == 'cyl': + if self.projection != 'cyl': xmin = (180./np.pi)*xmin; xmax = (180./np.pi)*xmax ymin = (180./np.pi)*ymin; ymax = (180./np.pi)*ymax # ypixels not given, find by scaling xpixels by the map aspect ratio. @@ -4268,8 +4283,8 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\ # print URL? if verbose: print(basemap_url) # return AxesImage instance. - return self.imshow(imread(urlopen(basemap_url)),ax=ax, - origin='upper') + img = Image.open(urlopen(basemap_url)) + return self.imshow(img, ax=ax, origin='upper') def wmsimage(self,server,\ xpixels=400,ypixels=None,\ diff --git a/lib/mpl_toolkits/basemap/test.py b/lib/mpl_toolkits/basemap/test.py index 8dfa7dae0..c7325a1ff 100644 --- a/lib/mpl_toolkits/basemap/test.py +++ b/lib/mpl_toolkits/basemap/test.py @@ -244,11 +244,21 @@ def test_optional_casting(self): class TestOrthoProjPolygons(TestCase): def test_basemapcreation_should_not_fail(self): - # different resolutions should work + # different resolutions should work for r in ['c', 'l', 'i', 'h', 'f']: m = Basemap(projection='ortho',resolution=r,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.) pass +@skipIf(not PY3, "Test skipped for Python 2.x as it requires PIL installed") +class TestArcgisimage(TestCase): + def test_cyl_proj_should_not_fail(self): + m = Basemap(projection='cyl', + llcrnrlon=-90,llcrnrlat=30, + urcrnrlon=-60,urcrnrlat=60) + m.arcgisimage(verbose=True) + + + def test(): """ Run some tests.