@@ -4257,9 +4257,9 @@ def pil_to_array(*args, **kwargs):
4257
4257
im ,c = self ._cliplimb (ax ,im )
4258
4258
return im
4259
4259
4260
- def arcgisimage (self ,server = ' http://server.arcgisonline.com/ArcGIS' ,\
4261
- service = ' World_Imagery' , xpixels = 400 ,ypixels = None ,\
4262
- dpi = 96 ,cachedir = None ,verbose = False ,** kwargs ):
4260
+ def arcgisimage (self , server = " http://server.arcgisonline.com/ArcGIS" ,
4261
+ service = " World_Imagery" , xpixels = 400 , ypixels = None ,
4262
+ dpi = 96 , cachedir = None , verbose = False , ** kwargs ):
4263
4263
"""
4264
4264
Retrieve an image using the ArcGIS Server REST API and display it on
4265
4265
the map. In order to use this method, the Basemap instance must be
@@ -4285,7 +4285,8 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
4285
4285
map projection region.
4286
4286
dpi The device resolution of the exported image (dots per
4287
4287
inch, default 96).
4288
- cachedir An optional directory to use as cache folder for the retrieved images.
4288
+ cachedir An optional directory to use as cache folder for the
4289
+ retrieved images.
4289
4290
verbose if True, print URL used to retrieve image (default
4290
4291
False).
4291
4292
============== ====================================================
@@ -4295,7 +4296,7 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
4295
4296
returns a matplotlib.image.AxesImage instance.
4296
4297
"""
4297
4298
4298
- # fix PIL import on some versions of OSX and scipy
4299
+ # Fix PIL import on some versions of OSX and scipy.
4299
4300
try :
4300
4301
from PIL import Image
4301
4302
except ImportError :
@@ -4305,28 +4306,30 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
4305
4306
raise ImportError ("arcgisimage method requires PIL "
4306
4307
"(http://pillow.readthedocs.io)" )
4307
4308
4308
- if not hasattr (self ,' epsg' ):
4309
+ if not hasattr (self , " epsg" ):
4309
4310
raise ValueError ("the Basemap instance must be created using "
4310
4311
"an EPSG code (http://spatialreference.org) "
4311
4312
"in order to use the wmsmap method" )
4312
- ax = kwargs .pop ('ax' , None ) or self ._check_ax ()
4313
- # find the x,y values at the corner points.
4313
+
4314
+ ax = kwargs .pop ("ax" , None ) or self ._check_ax ()
4315
+
4316
+ # Find the (x, y) values at the corner points.
4314
4317
with warnings .catch_warnings ():
4315
4318
warnings .simplefilter ("ignore" , category = FutureWarning )
4316
4319
p = pyproj .Proj (init = "epsg:%s" % self .epsg , preserve_units = True )
4317
- xmin ,ymin = p (self .llcrnrlon ,self .llcrnrlat )
4318
- xmax ,ymax = p (self .urcrnrlon ,self .urcrnrlat )
4320
+ xmin , ymin = p (self .llcrnrlon , self .llcrnrlat )
4321
+ xmax , ymax = p (self .urcrnrlon , self .urcrnrlat )
4319
4322
if self .projection in _cylproj :
4320
- Dateline = \
4321
- _geoslib .Point (self (180. ,0.5 * (self .llcrnrlat + self .urcrnrlat )))
4322
- hasDateline = Dateline .within (self ._boundarypolyxy )
4323
- if hasDateline :
4323
+ dateline = _geoslib .Point (self (180. , 0.5 * (self .llcrnrlat + self .urcrnrlat )))
4324
+ if dateline .within (self ._boundarypolyxy ):
4324
4325
raise ValueError ("arcgisimage cannot handle images that cross "
4325
4326
"the dateline for cylindrical projections" )
4326
- # ypixels not given, find by scaling xpixels by the map aspect ratio.
4327
+
4328
+ # If ypixels is not given, compute it with xpixels and aspect ratio.
4327
4329
if ypixels is None :
4328
- ypixels = int (self .aspect * xpixels )
4329
- # construct a URL using the ArcGIS Server REST API.
4330
+ ypixels = int (self .aspect * xpixels )
4331
+
4332
+ # Construct a URL using the ArcGIS Server REST API.
4330
4333
basemap_url = \
4331
4334
"%s/rest/services/%s/MapServer/export?\
4332
4335
bbox=%s,%s,%s,%s&\
@@ -4337,39 +4340,41 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
4337
4340
format=png32&\
4338
4341
transparent=true&\
4339
4342
f=image" % \
4340
- (server ,service ,xmin ,ymin ,xmax ,ymax ,self .epsg ,self .epsg ,xpixels ,ypixels ,dpi )
4341
- # print URL?
4342
- if verbose : print (basemap_url )
4343
+ (server , service , xmin , ymin , xmax , ymax , self .epsg , self .epsg , xpixels , ypixels , dpi )
4344
+
4345
+ # Print URL in verbose mode.
4346
+ if verbose :
4347
+ print (basemap_url )
4348
+
4349
+ if cachedir is not None :
4343
4350
4344
- if cachedir != None :
4345
4351
# Generate a filename for the cached file.
4346
4352
filename = "%s-bbox-%s-%s-%s-%s-bboxsr%s-imagesr%s-size-%s-%s-dpi%s.png" % \
4347
- (service ,xmin ,ymin ,xmax ,ymax ,self .epsg ,self .epsg ,xpixels ,ypixels ,dpi )
4353
+ (service , xmin , ymin , xmax , ymax , self .epsg , self .epsg , xpixels , ypixels , dpi )
4348
4354
4349
- # Check if the cache directory exists, if not create it.
4355
+ # Check if the cache directory exists, if not create it.
4350
4356
if not os .path .exists (cachedir ):
4351
4357
os .makedirs (cachedir )
4352
4358
4353
4359
# Check if the image is already in the cachedir folder.
4354
4360
cache_path = os .path .join (cachedir , filename )
4355
-
4356
4361
if os .path .isfile (cache_path ):
4357
4362
if verbose :
4358
- print (' Image already in cache' )
4363
+ print (" Image already in cache" )
4359
4364
img = Image .open (cache_path )
4360
- return self .imshow (img , ax = ax , origin = ' upper' )
4365
+ return self .imshow (img , ax = ax , origin = " upper" )
4361
4366
4362
4367
# Retrieve image from remote server.
4363
4368
import contextlib
4364
4369
conn = urlopen (basemap_url )
4365
4370
with contextlib .closing (conn ):
4366
4371
img = Image .open (conn )
4367
4372
# Save to cache if requested.
4368
- if cachedir != None :
4373
+ if cachedir is not None :
4369
4374
img .save (cache_path )
4370
4375
4371
4376
# Return AxesImage instance.
4372
- return self .imshow (img , ax = ax , origin = ' upper' )
4377
+ return self .imshow (img , ax = ax , origin = " upper" )
4373
4378
4374
4379
def wmsimage (self ,server ,\
4375
4380
xpixels = 400 ,ypixels = None ,\
0 commit comments