Skip to content

Commit b9c161b

Browse files
authored
Merge pull request #505 from guziy/fix_arcgis_image
Fix arcgisimage for cylindrical coordinates, remove imread
2 parents 84500e7 + 73a6285 commit b9c161b

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4229,6 +4229,21 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42294229
42304230
returns a matplotlib.image.AxesImage instance.
42314231
"""
4232+
4233+
4234+
# fix PIL import on some versions of OSX and scipy
4235+
try:
4236+
from PIL import Image
4237+
except ImportError:
4238+
try:
4239+
import Image
4240+
except ImportError:
4241+
msg = ('arcgisimage method requires PIL '
4242+
'(http://pillow.readthedocs.io)')
4243+
raise ImportError(msg)
4244+
4245+
4246+
42324247
if not hasattr(self,'epsg'):
42334248
msg = dedent("""
42344249
Basemap instance must be creating using an EPSG code
@@ -4248,7 +4263,7 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42484263
arcgisimage cannot handle images that cross
42494264
the dateline for cylindrical projections.""")
42504265
raise ValueError(msg)
4251-
if self.projection == 'cyl':
4266+
if self.projection != 'cyl':
42524267
xmin = (180./np.pi)*xmin; xmax = (180./np.pi)*xmax
42534268
ymin = (180./np.pi)*ymin; ymax = (180./np.pi)*ymax
42544269
# ypixels not given, find by scaling xpixels by the map aspect ratio.
@@ -4269,8 +4284,8 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42694284
# print URL?
42704285
if verbose: print(basemap_url)
42714286
# return AxesImage instance.
4272-
return self.imshow(imread(urlopen(basemap_url)),ax=ax,
4273-
origin='upper')
4287+
img = Image.open(urlopen(basemap_url))
4288+
return self.imshow(img, ax=ax, origin='upper')
42744289

42754290
def wmsimage(self,server,\
42764291
xpixels=400,ypixels=None,\

lib/mpl_toolkits/basemap/test.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,21 @@ def test_optional_casting(self):
244244

245245
class TestOrthoProjPolygons(TestCase):
246246
def test_basemapcreation_should_not_fail(self):
247-
# different resolutions should work
247+
# different resolutions should work
248248
for r in ['c', 'l', 'i', 'h', 'f']:
249249
m = Basemap(projection='ortho',resolution=r,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
250250
pass
251251

252+
@skipIf(not PY3, "Test skipped for Python 2.x as it requires PIL installed")
253+
class TestArcgisimage(TestCase):
254+
def test_cyl_proj_should_not_fail(self):
255+
m = Basemap(projection='cyl',
256+
llcrnrlon=-90,llcrnrlat=30,
257+
urcrnrlon=-60,urcrnrlat=60)
258+
m.arcgisimage(verbose=True)
259+
260+
261+
252262
def test():
253263
"""
254264
Run some tests.

0 commit comments

Comments
 (0)