Skip to content

Commit c4a19b7

Browse files
committed
Fix arcgisimage for cylindrical coordinates, remove imread as it is not able to open urls
1 parent 3076ec9 commit c4a19b7

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/mpl_toolkits/basemap/__init__.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -4228,6 +4228,21 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42284228
42294229
returns a matplotlib.image.AxesImage instance.
42304230
"""
4231+
4232+
4233+
# fix PIL import on some versions of OSX and scipy
4234+
try:
4235+
from PIL import Image
4236+
except ImportError:
4237+
try:
4238+
import Image
4239+
except ImportError:
4240+
msg = ('warpimage method requires PIL '
4241+
'(http://pillow.readthedocs.io)')
4242+
raise ImportError(msg)
4243+
4244+
4245+
42314246
if not hasattr(self,'epsg'):
42324247
msg = dedent("""
42334248
Basemap instance must be creating using an EPSG code
@@ -4247,7 +4262,7 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42474262
arcgisimage cannot handle images that cross
42484263
the dateline for cylindrical projections.""")
42494264
raise ValueError(msg)
4250-
if self.projection == 'cyl':
4265+
if self.projection != 'cyl':
42514266
xmin = (180./np.pi)*xmin; xmax = (180./np.pi)*xmax
42524267
ymin = (180./np.pi)*ymin; ymax = (180./np.pi)*ymax
42534268
# 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',\
42684283
# print URL?
42694284
if verbose: print(basemap_url)
42704285
# return AxesImage instance.
4271-
return self.imshow(imread(urlopen(basemap_url)),ax=ax,
4272-
origin='upper')
4286+
img = Image.open(urlopen(basemap_url))
4287+
return self.imshow(img, ax=ax, origin='upper')
42734288

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

lib/mpl_toolkits/basemap/test.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,20 @@ 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+
class TestArcgisimage(TestCase):
253+
def test_cyl_proj_should_not_fail(self):
254+
m = Basemap(projection='cyl',
255+
llcrnrlon=-90,llcrnrlat=30,
256+
urcrnrlon=-60,urcrnrlat=60)
257+
m.arcgisimage(verbose=True)
258+
259+
260+
252261
def test():
253262
"""
254263
Run some tests.

0 commit comments

Comments
 (0)