Comments (18)
I am having the same issue.
from contextily.
Thanks! I guess that we just cut a release with the new default and point users to new Stadia service if they want to keep using Stamen tiles.
from contextily.
Thank you, I did not realize I needed to register! Worked fine once I added the API key to the URL 🙌
For reference:
- https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}{r}.png gives the
ValueError
- https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}.png gives the
ValueError
- https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}@2x.png gives a plot with the warning tiles
Adding an API key from the Stadia Maps registration to any of these URLs provided the map as expected.
from contextily.
@peanutfun Good to gear you got it sorted :) For anyone finding this issue wanting to know the full resolution, here are some details that I think should help.
We have been basically letting everything slide through since the deprecation announcement in July, but these tiles DO require an API key going forward. I'm not up on whether contextily has a way to manage API keys, but you can add it as a query string parameter like ?api_key=YOUR-API-KEY-HERE
to your URLs.
@jorisvandenbossche has the right idea. Stamen never collected any information on who was using their tiles, so there was no way to contact everyone using the old Fastly URLs. The solution we settled on was a "warning" tile. Since ~1 week ago, all unauthenticated requests will now get these warning tiles pseudo-randomly. Currently it's ~every 16th tile on the map, and will increase as the old URL shutoff date approaches.
from contextily.
Because Stadia allows both domain whitelisting and API key authentication, passing the key requires a bit more than usual. See the snippet below.
import geopandas
import geodatasets
import contextily
nybb = geopandas.read_file(geodatasets.get_path("nybb")).to_crs(3857)
# get the provider object to adapt
tiles = contextily.providers.Stadia.StamenToner
tiles["url"] = tiles["url"] + "?api_key={api_key}" # adding API key placeholder
ax = nybb.plot(alpha=.5)
contextily.add_basemap(ax=ax, source=tiles(api_key="my_key_here"))
from contextily.
Having the same issue outside of Jupyter notebook (using Spyder, personally). Same issue pops up even with the most basic example from the documentation.
import contextily as cx
import geopandas
data_url = "https://ndownloader.figshare.com/files/20232174"
db = geopandas.read_file(data_url)
ax = db.plot(color="red", figsize=(9, 9))
cx.add_basemap(ax, crs=db.crs.to_string())
File C:\ProgramData\Miniconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\kchudler\onedrive - research triangle institute\documents\hydromet_tools\storm_analysis_system\untitled1.py:18
cx.add_basemap(ax, crs=db.crs.to_string())
File C:\ProgramData\Miniconda3\lib\site-packages\contextily\plotting.py:129 in add_basemap
image, extent = bounds2img(
File C:\ProgramData\Miniconda3\lib\site-packages\contextily\tile.py:225 in bounds2img
merged, extent = _merge_tiles(tiles, arrays)
File C:\ProgramData\Miniconda3\lib\site-packages\contextily\tile.py:628 in _merge_tiles
img[y * h : (y + 1) * h, x * w : (x + 1) * w, :] = arr
ValueError: could not broadcast input array from shape (512,512,4) into shape (256,256,4)
from contextily.
This seems to be an issue with Stamen Terrain tiles. The code from the @chudlerk's post fetches 9 tiles, but their shape are not consistent
(256, 256, 4), (256, 256, 4), (256, 256, 4), (256, 256, 4), (256, 256, 4), (256, 256, 4), (256, 256, 4), (256, 256, 4), (512, 512, 4)
See that the last one has double the resolution. I wonder if that is intention or some artifact of the transition to Stadia tile service. Maybe @ianthetechie will know?
In the meantime, you can use different tiles which do not seem to have the same issue, like cx.providers.OpenStreetMap.HOT
or any other.
from contextily.
Can you try with a different provider source? For example cx.add_basemap(ax, source=cx.providers.OpenStreetMap.Mapnik)
I think this error is due because the default of Stamen is going to be removed (see #220), and it seems that they now changed the tiles to have a message, like:
for https://stamen-tiles-a.a.ssl.fastly.net/terrain/6/28/23.png. And this image has a size of 512x512 instead of 256x256 like the normal tiles.
from contextily.
I suppose they give you such a tile once every few or with some logic, so that we see only some of the tiles have this other size.
In any case, time to do a release so we have the changed default out?
from contextily.
In any case, time to do a release so we have the changed default out?
Ideally with #222 in and a fix for tests (not sure how, yet, probably by relaxing the checks or depending on more stable tiles).
from contextily.
Hey, thanks for the summons @martinfleis.
See that the last one has double the resolution. I wonder if that is intention or some artifact of the transition to Stadia tile service.
That'd be a bit of an accident. We currently don't discriminate on the 1x/2x resolution on these error tiles since most maps display them correctly. As @jorisvandenbossche noticed, we started serving these "brownout" warning tiles yesterday for every 16th tile. We will increase the frequency as the month goes on. If you access the tiles using a Stadia Maps API key, you'll get the correct tiles.
Stamen announced back in July (https://maps.stamen.com/stadia-partnership/) that they were shutting down their Fastly CDN as it became too expensive. You will need an API key to continue access Stamen tiles. They remain free for non-commercial use, but commercial use and higher volumes require a paid plan. You can sign up for a key here: https://stadiamaps.com/stamen/onboarding/create-account.
from contextily.
Sounds good. You know where to shout if you need some help with that (or just a quick once-over). You can find the updated URLs here: https://docs.stadiamaps.com/guides/migrating-from-stamen-map-tiles/#switch-your-tile-urls.
from contextily.
Can you try with a different provider source? For example
cx.add_basemap(ax, source=cx.providers.OpenStreetMap.Mapnik)
I think this error is due because the default of Stamen is going to be removed (see #220), and it seems that they now changed the tiles to have a message, like:
for https://stamen-tiles-a.a.ssl.fastly.net/terrain/6/28/23.png. And this image has a size of 512x512 instead of 256x256 like the normal tiles.
Yes, using a different provider source provided an acceptable workaround.
from contextily.
Thanks! I guess that we just cut a release with the new default and point users to new Stadia service if they want to keep using Stamen tiles.
Sounds good. Thanks.
from contextily.
I still experience the original issue when switching to the new Stamen URLs at the Stadia service:
>>> contextily.add_basemap(plt.gca(), source="https://tiles.stadiamaps.com/tiles/stamen_toner_lite/{z}/{x}/{y}{r}.png")
ValueError: could not broadcast input array from shape (256,256,4) into shape (512,512,4)
It seems like the resolution of the tiles changed and contextily cannot handle that. Is there any workaround? I would like to keep using the Stamen maps with contextily.
from contextily.
It seems that new link is still giving the same "warning" tiles every x requests (eg I tried https://tiles.stadiamaps.com/tiles/stamen_toner_lite/3/1/1.png several times). Maybe that's because you didn't provide an API key? (if that's the case)
from contextily.
@ianthetechie would it be possible to generate a version of the warning tile at 256x256 ?
from contextily.
Yeah, that's a good question @jorisvandenbossche. I'll look into that. Our current tile is 512 because all the major web renderers handle it fine, but we probably should offer a 256 version as well.
from contextily.
Related Issues (20)
- Change package home in `setup.py`
- _calculate_zoom returns negative values if coordinates in epsg:3857 are passed HOT 3
- Question: Is there a way to clip to a polygon using add_basemap()? HOT 2
- Using contextily adds blank space to the right of a matplotlib panel plot
- BUG: HTTPError for points close together
- CI failing HOT 3
- Force basemap to be greyscale HOT 3
- Caching and terms of service? HOT 2
- Wrong lat and lon from contextily bbox HOT 3
- No Gaode provider? HOT 2
- attributions severely wrapped upon savefig HOT 1
- Mistake in matching basemap through contextily HOT 2
- Reset_extent is not behaving as expected with local file when raster extents is smaller than the shape extents. HOT 2
- Add the ability to fetch tiles in parallel HOT 8
- Add timeout parameter to add_basemap HOT 1
- Save as editable object HOT 2
- Change the default basemap from Stamen HOT 2
- Input array error when loading contextily basemap HOT 1
- SSLError HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contextily.