You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
arcgisimage - urllib2.HTTPError: HTTP Error 400: Bad Request #546
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
map = Basemap(llcrnrlon=3.75,llcrnrlat=39.75,urcrnrlon=4.35,urcrnrlat=40.15, epsg=5520)
#http://server.arcgisonline.com/arcgis/rest/services
map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels = 1500, verbose= True)
plt.show()
I get the following error:
http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/export?bbox=89626124.1385,252193030.113,92533661.1526,254772111.328&bboxSR=5520&imageSR=5520&size=1500,1330&dpi=96&format=png32&transparent=true&f=image
Traceback (most recent call last):
File "plot_map.py", line 73, in <module>
map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels = 1500, verbose= True)
File "/home/mwlock2/.local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 4308, in arcgisimage
img = Image.open(urlopen(basemap_url))
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 435, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 467, in error
result = self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 654, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/lib/python2.7/urllib2.py", line 435, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 473, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
When trying to use World_Imagery as replacement for ESRI_Imagery_World_2D, there are issues with the EPSG values defined in the URL attributes (exact problem still not identified).
I do not have any idea why this if-block is there (it looks like a radian-to-degree conversion), but this recalculation of the coordinates xmin, xmax, ymin and ymax is overwriting the correct transformed coordinates with wrong values. So I am getting a blank image because in fact I am requesting to the REST API one region outside the map.
For the record, if I comment this if-block in my installed basemap library and run the snippet with the new World_Imagery map:
. It is complicated, with lots of if-branching, but this would tell you what units those attributes should be in when the Basemap object is initialized. My suspicion is that there was a time when the lat/lon bounds would be recorded in radians except for cylindrical projection, but then a future change in the init made them always in degrees.
@matthew-william-lock May I ask you to check if the patch works for you? You would need to install basemap using the temporary bugfix-546 branch first:
The default value for the service argument used to be "ESRI_Imagery_World_2D", so I also changed it to the new default value "World_Imagery" so that the default behaviour works again.
Activity
PowerBroker2 commentedon Jul 30, 2022
I'm getting a very similar error, too
molinav commentedon Aug 6, 2022
There seems to be some problem with this concrete ESRI REST API service
ESRI_Imagery_World_2D, it might be that ESRI has removed it:https://www.arcgis.com/home/item.html?id=39758ebd4b9642b79e7a2f54d8871556
Quoted from the link above:
The alternative service that they recommend is the
World_Imageryservice:https://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9
This other service seems to work with an example link that I was trying directly on the browser:
But if I try with the link of your example and replace
ESRI_Imagery_World_2DwithWorld_Imagery, I just get a blank image:molinav commentedon Aug 6, 2022
I think that my
World_Imageryexamples are not behaving properly because the URL attributesbboxSRandimageSRare not set correctly.molinav commentedon Aug 6, 2022
If I try to use simple cylindrical coordinates (EPSG=4326), the code snippet works:
So there are at least two problems:
ESRI_Imagery_World_2Dis defunct since May 2022.World_Imageryas replacement forESRI_Imagery_World_2D, there are issues with the EPSG values defined in the URL attributes (exact problem still not identified).molinav commentedon Aug 6, 2022
@matthew-william-lock I have found that the following block is causing the problems with the EPSG 5520 coordinates:
basemap/packages/basemap/src/mpl_toolkits/basemap/__init__.py
Lines 4287 to 4289 in f370fd3
I do not have any idea why this if-block is there (it looks like a radian-to-degree conversion), but this recalculation of the coordinates
xmin,xmax,yminandymaxis overwriting the correct transformed coordinates with wrong values. So I am getting a blank image because in fact I am requesting to the REST API one region outside the map.For the record, if I comment this if-block in my installed
basemaplibrary and run the snippet with the newWorld_Imagerymap:then the verbose output that I get is the following link (note the change in the
bboxvalues):and the following image (i.e. what you were expecting from the example):
I would need to inspect why this if-block was added in the past, I have no idea.
WeatherGod commentedon Aug 6, 2022
A good place to look to find out what exactly things are in which situation is the
__init__()mega-function:basemap/packages/basemap/src/mpl_toolkits/basemap/__init__.py
Line 592 in f370fd3
molinav commentedon Aug 7, 2022
@matthew-william-lock May I ask you to check if the patch works for you? You would need to install
basemapusing the temporarybugfix-546branch first:After that, you can try the updated Python example snippet (note that I now use "World_Imagery" as service):
The default value for the service argument used to be "ESRI_Imagery_World_2D", so I also changed it to the new default value "World_Imagery" so that the default behaviour works again.
molinav commentedon Aug 10, 2022
I will close this issue as completed with PR #548. If you still experience problems, please feel free to reopen it.