Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arcgisimage doesn't work #591

Closed
Jinyin-Hu opened this issue Oct 19, 2023 · 4 comments
Closed

arcgisimage doesn't work #591

Jinyin-Hu opened this issue Oct 19, 2023 · 4 comments

Comments

@Jinyin-Hu
Copy link

I tried to use arcgisimage to plot a background map, but found it not working any way. And the example/testarcgis.py is also not working. Any help with this? Thanks

matplotlib version: 3.6.2
basemap version: 1.2.2 (same issue with 1.3.8)

these are the print information when runing testarcgis.py

http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/export?bbox=-5156.620156177409,1718.8733853924696,-3437.746770784939,3437.746770784939&bboxSR=4326&imageSR=4326&size=400,400&dpi=96&format=png32&transparent=true&f=image

HTTPError Traceback (most recent call last)
/var/folders/_m/wrfhq7ws5lj9_z9rjlf9bp6d_ll1t2/T/ipykernel_9229/3229385272.py in <cell line: 13>()
11 m=Basemap(projection='cyl',llcrnrlon=-90,llcrnrlat=30,urcrnrlon=-60,urcrnrlat=60,resolution='i')
12 # default 'blue marble' image.
---> 13 m.arcgisimage(verbose=True)
14 m.drawmeridians(np.arange(-180,180,10),labels=[0,0,0,1],color='y')
15 m.drawparallels(np.arange(-90,90,10),labels=[1,0,0,0],color='y')

~/opt/anaconda3/envs/mti/lib/python3.8/site-packages/mpl_toolkits/basemap/init.py in arcgisimage(self, server, service, xpixels, ypixels, dpi, verbose, **kwargs)
4271 if verbose: print(basemap_url)
4272 # return AxesImage instance.
-> 4273 return self.imshow(imread(urlopen(basemap_url)),ax=ax,
4274 origin='upper')
4275

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in http_response(self, request, response)
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
642

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in error(self, proto, *args)
561 http_err = 0
562 args = (dict, proto, meth_name) + args
--> 563 result = self._call_chain(*args)
564 if result:
565 return result

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in http_error_302(self, req, fp, code, msg, headers)
753 fp.close()
754
--> 755 return self.parent.open(new, timeout=req.timeout)
756
757 http_error_301 = http_error_303 = http_error_307 = http_error_302

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in http_response(self, request, response)
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
642

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
570
571 # XXX probably also want an abstract factory that knows when it makes

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result

~/opt/anaconda3/envs/mti/lib/python3.8/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 400: Bad Request

@molinav
Copy link
Member

molinav commented Nov 19, 2023

Hi @Jinyin-Hu! Can you recheck that your issue occurs with basemap 1.3.8 and it is not a problem related to the local environments? Your issue is caused by the sunsetting of "ESRI_Imagery_World_2D" in ArcGIS, which used to be the default link used by Basemap.arcgisimage. This default link was changed for basemap 1.3.4 (#548) so that it uses "World_Imagery" instead.

Your traceback shows an URL pointing to "ESRI_Imagery_World_2D", so I would expect that the script was run with a basemap version before 1.3.4.

You can check with the following minimal example:

import sys
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import basemap
from mpl_toolkits.basemap import Basemap

print("Python version:", sys.version_info)
print("Basemap version:", basemap.__version__)

bmap = Basemap(projection="cyl", resolution="i",
               llcrnrlon=-90, llcrnrlat=30,
               urcrnrlon=-60, urcrnrlat=60)

bmap.arcgisimage(verbose=True)
bmap.drawmeridians(np.linspace(-180, 180, 37),
                   labels=[0, 0, 0, 1], color="y")
bmap.drawparallels(np.linspace(-90, 90, 19),
                   labels=[1, 0, 0, 0], color="y")
plt.savefig("example.png")

In my case I get the following:

Python version: sys.version_info(major=3, minor=11, micro=2, releaselevel='final', serial=0)
Basemap version: 1.3.8

example

@molinav
Copy link
Member

molinav commented Nov 23, 2023

Hi @Jinyin-Hu! Did you have time to check my example?

@Jinyin-Hu
Copy link
Author

Hi @molinav, it works when using the same versions of python and basemap as yours. Yeah! thanks so much for your reply. I

Hi @Jinyin-Hu! Did you have time to check my example?

@molinav
Copy link
Member

molinav commented Nov 24, 2023

Nice to hear it! I am closing this issue then.

@molinav molinav closed this as completed Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants