I am creating a mapping application with Python and Cartopy, and attempting to use open-source map tiles for backgrounds, to have more options than the default Cartopy map.
It works perfectly for maps that are zoomed in fairly close, but when I try to get a view from a higher elevation, something fails. If I have the zoom set to 11, it works. If I set it to 12, it hangs indefinitely and gives no traceback.
Same result with both the OSM and Stamen map servers.
Here is a short, self-contained example (note that a line or two may be artifacts from the various ways I've tried this)
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.io.img_tiles as cimgt
def custom_background(source_point):
source_point = source_point.split(" ")
source_point = (float(source_point[0]), float(source_point[1]))
dx = 1.5
dy = 1.5
lon_min, lon_max = source_point[0]-dx, source_point[0]+dx
lat_min, lat_max = source_point[1]-dy, source_point[1]+dy
zoom = 7
map_url = "https://www.openstreetmap.org/#map={}/{}/{}".format(zoom,source_point[0],source_point[1])
tile = cimgt.OSM(url=map_url)
tile = cimgt.StamenTerrain()
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([lat_min, lat_max, lon_min, lon_max])
ax.add_image(tile, zoom)
#~ ax.add_image(tile)
return ax
custom_background("45.068466 -66.45477")
plt.savefig("tile.png")
the result, with zoom = 7:
but if I were to change zoom to say, 14, the program will not complete no matter how long I allow it to run.
The url parameter that is passed to cimgt.OSM() is optional. I get the same result with or without it. (See: https://scitools.org.uk/cartopy/docs/v0.16/cartopy/io/img_tiles.html#cartopy.io.img_tiles.OSM)
Am I missing something here? Any help would be appreciated, thank you.