1
votes

I am having problems with basemap - arcgisimage function. Sample code below

...

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from PIL import Image

m = Basemap(
    llcrnrlat=40.361369, llcrnrlon=-80.0955278,
    urcrnrlat=40.501368, urcrnrlon=-79.865723,
    epsg = 2272
)
#m.arcgisimage(service='ESRI_StreetMap_World_2D'
, xpixels=7000, verbose=True)
m.arcgisimage(service='World_Physical_Map', xpixels=7000, ypixels=None, dpi=96,verbose=True)

#m.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=7000, verbose=True)

plt.show()

...

when I run this the arcgisimage() function crashes in PIL with error message

Traceback (most recent call last):
  File "C:\Machine Learning\Geospatial\pittsburgh_map.py", line 11, in <module>
    m.arcgisimage(service='World_Physical_Map', xpixels=7000, ypixels=None, dpi=96,verbose=True)
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 4263, in arcgisimage
    return self.imshow(imread(urlopen(basemap_url)),ax=ax,
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\image.py", line 1490, in imread
    with img_open(fname) as image:
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\ImageFile.py", line 121, in __init__
    self._open()
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\PngImagePlugin.py", line 692, in _open
    cid, pos, length = self.png.read()
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\PngImagePlugin.py", line 162, in read
    pos = self.fp.tell()
io.UnsupportedOperation: seek
2
How did you install mpl_toolkits? Make sure you’re following Basemap installation instructions: matplotlib.org/basemap/users/installing.html - Alex Walczak
thanks am running on windows 10 and there were issues installing. I think pip or conda finally worked. the link seems to refer to linux? - Peter3103
which method would you recommend? I have py 3.8.6 installed. Initially I had 3.9 but had to go to an earlier version to get libraries that were compatible. Everything else seems to work in basemap except for this arcgisimage() function - Peter3103
The link also gives info on the Windows binaries — that’s what I’d use to install. Edit: basemap is deprecated in favor of cartopy github.com/matplotlib/basemap - Alex Walczak
I used conda or pip with a .whl file - not quite sure since it was very hard to install. I thought those instructions were for linux? basemap seems to work except for the arcgisimage() function. does this need another library to work - Peter3103

2 Answers

1
votes

I had the same problem, most probably you have installed it using conda. I deinstalled the basemap module and reinstalled it with pip. then everything worked normally

0
votes

If you followed the basemap installation instructions, then any issues you have with running basemap will probably remain unfixed as it is is deprecated in favor of cartopy https://github.com/matplotlib/basemap.