@@ -4260,40 +4260,50 @@ def pil_to_array(*args, **kwargs):
4260
4260
def arcgisimage (self , server = "http://server.arcgisonline.com/ArcGIS" ,
4261
4261
service = "World_Imagery" , xpixels = 400 , ypixels = None ,
4262
4262
dpi = 96 , cachedir = None , verbose = False , ** kwargs ):
4263
- """
4264
- Retrieve an image using the ArcGIS Server REST API and display it on
4265
- the map. In order to use this method, the Basemap instance must be
4266
- created using the ``epsg`` keyword to define the map projection, unless
4267
- the ``cyl`` projection is used (in which case the epsg code 4326 is
4268
- assumed).
4263
+ r"""Display background image using ArcGIS Server REST API.
4269
4264
4270
- .. tabularcolumns:: |l|L|
4265
+ In order to use this method, the :class:`Basemap` instance
4266
+ must be created using the ``epsg`` keyword to define the
4267
+ map projection, unless the "cyl" projection is used (in
4268
+ which case the EPSG code 4326 is assumed).
4271
4269
4272
- ============== ====================================================
4273
- Keywords Description
4274
- ============== ====================================================
4275
- server web map server URL (default
4276
- http://server.arcgisonline.com/ArcGIS).
4277
- service service (image type) hosted on server (default
4278
- 'World_Imagery', which is NASA 'Blue Marble'
4279
- image).
4280
- xpixels requested number of image pixels in x-direction
4281
- (default 400).
4282
- ypixels requested number of image pixels in y-direction.
4283
- Default (None) is to infer the number from
4284
- from xpixels and the aspect ratio of the
4285
- map projection region.
4286
- dpi The device resolution of the exported image (dots per
4287
- inch, default 96).
4288
- cachedir An optional directory to use as cache folder for the
4289
- retrieved images.
4290
- verbose if True, print URL used to retrieve image (default
4291
- False).
4292
- ============== ====================================================
4270
+ Parameters
4271
+ ----------
4293
4272
4294
- Extra keyword ``ax`` can be used to override the default axis instance.
4273
+ server : str, optional
4274
+ base URL of the web map server
4295
4275
4296
- returns a matplotlib.image.AxesImage instance.
4276
+ service : str, optional
4277
+ service (image type) hosted by the server
4278
+
4279
+ xpixels : int, optional
4280
+ requested number of image pixels in the `x`-direction
4281
+
4282
+ ypixels : int, optional
4283
+ requested number of image pixels in the `y`-direction;
4284
+ if not given, it is inferred from ``xpixels`` and the
4285
+ aspect ratio of the map projection region
4286
+
4287
+ dpi : int, optional
4288
+ device resolution of the exported image
4289
+
4290
+ cachedir : str, optional
4291
+ if given, directory to use as cache folder for the images
4292
+ retrieved from the server
4293
+
4294
+ verbose : bool, optional
4295
+ if True, print debugging information
4296
+
4297
+ \**kwargs : dict, optional
4298
+ keyword-only arguments; currently, only ``ax`` is supported
4299
+ to override the default :class:`matplotlib.axes.Axes`
4300
+ instance
4301
+
4302
+ Returns
4303
+ -------
4304
+
4305
+ aximg : matplotlib.image.AxesImage
4306
+ image axes instance
4297
4307
"""
4298
4308
4299
4309
# Fix PIL import on some versions of OSX and scipy.
@@ -4313,7 +4323,7 @@ def arcgisimage(self, server="http://server.arcgisonline.com/ArcGIS",
4313
4323
4314
4324
ax = kwargs .pop ("ax" , None ) or self ._check_ax ()
4315
4325
4316
- # Find the (x, y) values at the corner points.
4326
+ # Find the ` (x, y)` values at the corner points.
4317
4327
with warnings .catch_warnings ():
4318
4328
warnings .simplefilter ("ignore" , category = FutureWarning )
4319
4329
p = pyproj .Proj (init = "epsg:%s" % self .epsg , preserve_units = True )
@@ -4346,34 +4356,30 @@ def arcgisimage(self, server="http://server.arcgisonline.com/ArcGIS",
4346
4356
if verbose :
4347
4357
print (basemap_url )
4348
4358
4359
+ # Try to return fast if cache is enabled.
4349
4360
if cachedir is not None :
4350
-
4351
4361
# Generate a filename for the cached file.
4352
4362
filename = "%s-bbox-%s-%s-%s-%s-bboxsr%s-imagesr%s-size-%s-%s-dpi%s.png" % \
4353
4363
(service , xmin , ymin , xmax , ymax , self .epsg , self .epsg , xpixels , ypixels , dpi )
4354
-
4355
4364
# Check if the cache directory exists, if not create it.
4356
4365
if not os .path .exists (cachedir ):
4357
4366
os .makedirs (cachedir )
4358
-
4359
- # Check if the image is already in the cachedir folder.
4367
+ # Return fast if the image is already in the cache.
4360
4368
cache_path = os .path .join (cachedir , filename )
4361
4369
if os .path .isfile (cache_path ):
4362
4370
if verbose :
4363
4371
print ("Image already in cache" )
4364
4372
img = Image .open (cache_path )
4365
4373
return self .imshow (img , ax = ax , origin = "upper" )
4366
4374
4367
- # Retrieve image from remote server.
4375
+ # Retrieve image from the remote server.
4368
4376
import contextlib
4369
4377
conn = urlopen (basemap_url )
4370
4378
with contextlib .closing (conn ):
4371
4379
img = Image .open (conn )
4372
4380
# Save to cache if requested.
4373
4381
if cachedir is not None :
4374
4382
img .save (cache_path )
4375
-
4376
- # Return AxesImage instance.
4377
4383
return self .imshow (img , ax = ax , origin = "upper" )
4378
4384
4379
4385
def wmsimage (self ,server ,\
0 commit comments