@@ -4257,9 +4257,9 @@ def pil_to_array(*args, **kwargs):
42574257 im ,c = self ._cliplimb (ax ,im )
42584258 return im
42594259
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 ):
42634263 """
42644264 Retrieve an image using the ArcGIS Server REST API and display it on
42654265 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',\
42854285 map projection region.
42864286 dpi The device resolution of the exported image (dots per
42874287 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.
42894290 verbose if True, print URL used to retrieve image (default
42904291 False).
42914292 ============== ====================================================
@@ -4295,7 +4296,7 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42954296 returns a matplotlib.image.AxesImage instance.
42964297 """
42974298
4298- # fix PIL import on some versions of OSX and scipy
4299+ # Fix PIL import on some versions of OSX and scipy.
42994300 try :
43004301 from PIL import Image
43014302 except ImportError :
@@ -4305,28 +4306,30 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
43054306 raise ImportError ("arcgisimage method requires PIL "
43064307 "(http://pillow.readthedocs.io)" )
43074308
4308- if not hasattr (self ,' epsg' ):
4309+ if not hasattr (self , " epsg" ):
43094310 raise ValueError ("the Basemap instance must be created using "
43104311 "an EPSG code (http://spatialreference.org) "
43114312 "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.
43144317 with warnings .catch_warnings ():
43154318 warnings .simplefilter ("ignore" , category = FutureWarning )
43164319 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 )
43194322 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 ):
43244325 raise ValueError ("arcgisimage cannot handle images that cross "
43254326 "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.
43274329 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.
43304333 basemap_url = \
43314334"%s/rest/services/%s/MapServer/export?\
43324335 bbox=%s,%s,%s,%s&\
@@ -4337,39 +4340,41 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
43374340 format=png32&\
43384341 transparent=true&\
43394342 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 :
43434350
4344- if cachedir != None :
43454351 # Generate a filename for the cached file.
43464352 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 )
43484354
4349- # Check if the cache directory exists, if not create it.
4355+ # Check if the cache directory exists, if not create it.
43504356 if not os .path .exists (cachedir ):
43514357 os .makedirs (cachedir )
43524358
43534359 # Check if the image is already in the cachedir folder.
43544360 cache_path = os .path .join (cachedir , filename )
4355-
43564361 if os .path .isfile (cache_path ):
43574362 if verbose :
4358- print (' Image already in cache' )
4363+ print (" Image already in cache" )
43594364 img = Image .open (cache_path )
4360- return self .imshow (img , ax = ax , origin = ' upper' )
4365+ return self .imshow (img , ax = ax , origin = " upper" )
43614366
43624367 # Retrieve image from remote server.
43634368 import contextlib
43644369 conn = urlopen (basemap_url )
43654370 with contextlib .closing (conn ):
43664371 img = Image .open (conn )
43674372 # Save to cache if requested.
4368- if cachedir != None :
4373+ if cachedir is not None :
43694374 img .save (cache_path )
43704375
43714376 # Return AxesImage instance.
4372- return self .imshow (img , ax = ax , origin = ' upper' )
4377+ return self .imshow (img , ax = ax , origin = " upper" )
43734378
43744379 def wmsimage (self ,server ,\
43754380 xpixels = 400 ,ypixels = None ,\
0 commit comments