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

ENH: Add Stadia Maps image tile server class #2269

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

greglucas
Copy link
Contributor

The Stamen tiles are now being served by Stadia Maps. Stadia Maps requires an API key and has different naming conventions for their tiles, so create a new class to interact with the new server. Replaces #2266

xref: https://stamen.com/stamen-x-stadia-the-end-of-the-road-for-stamens-legacy-map-tiles/

Apparently, we don't have any tests for this... I did make an API key and test locally with the examples and those did seem to work.

cc @lgolston @ianthetechie

Copy link

@ianthetechie ianthetechie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor change request and question out of my ignorance :) Thanks for the ping @greglucas!

def __init__(self, apikey, style='alidade_smooth', cache=False):
super().__init__(cache=cache)
self.apikey = apikey
if style in ("alidade_satellite", "stamen_watercolor"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes on alidade_satellite that'd be really easy to miss in our docs...

  1. We don't actually support this as a full rendered style at the moment (this style ID won't actually work).
  2. The JPGs that do exist under a slightly different URL are for the raw imagery imagery only and are not a standard 256x256 tile but rather @2x 512 tiles, which are intended to be used in conjuction with a vector style.

The terms on this raw imagery are also a little different per our upstream provider (some details here: https://docs.stadiamaps.com/map-styles/alidade-satellite/), so I TL;DR I would suggest not adding this condition for the satellite style or mentioning it. We do intend to add this as a "normal" raster style in the future with the other layers on top, but it's probably best to just remove this for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info, I removed the satellite option for now.

def _image_url(self, tile):
x, y, z = tile
return ("http://tiles.stadiamaps.com/tiles/"
f"{self.style}/{z}/{x}/{y}.{self.extension}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question more than anything as I regrettably haven't used CartoPy myself, but are @2x (aka retina or 512 tiles) useful? If so, we do support those on all styles except for Stamen Watercolor by adding @2x right before the extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 It is easy enough to add, so I added an extension parameter as well now and it looks good locally to me.

@rcomer rcomer linked an issue Oct 13, 2023 that may be closed by this pull request
@lgolston
Copy link
Contributor

Thanks @greglucas! This will be a nice enhancement switching things over to Stadia. It looks good to me, except I think the desired_tile_form input should be kept?

@greglucas
Copy link
Contributor Author

Thanks @greglucas! This will be a nice enhancement switching things over to Stadia. It looks good to me, except I think the desired_tile_form input should be kept?

Yeah, I wasn't entirely sure what the desired_tile_form was used for and how it was chosen for the various tile styles. I don't see any mention of anything like RGB / RGBA on the Stadia or Stamen website, so I figured we would just leave it out for now and if a user wants a specific form we can add it later? Most of the other classes don't have the desired_tile_form either which is why I dropped it.

@lgolston
Copy link
Contributor

Thanks @greglucas! This will be a nice enhancement switching things over to Stadia. It looks good to me, except I think the desired_tile_form input should be kept?

Yeah, I wasn't entirely sure what the desired_tile_form was used for and how it was chosen for the various tile styles. I don't see any mention of anything like RGB / RGBA on the Stadia or Stamen website, so I figured we would just leave it out for now and if a user wants a specific form we can add it later? Most of the other classes don't have the desired_tile_form either which is why I dropped it.

I don't see it explicitly mentioned but plotting, for instance, stamen_toner_labels without having desired_tile_form gives a warning from PIL\Image.py:992: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images. It seems a necessary if anyone is using the sub-styles that are just overlaying lines/labels and not a full image

The Stamen tiles are now being served by Stadia Maps. Stadia Maps
requires an API key, and has different naming convention for their
tiles, so create a new class to interact with the new server.
@greglucas
Copy link
Contributor Author

Thanks for identifying that @lgolston. Rather than trying to special-case the various tile styles, I think it might be easier to just go straight to RGBA for all of Stadia so we can also accommodate potential future styles as well without needing to explicitly handle each style's version. This does add an extra alpha channel to the other images when they aren't explicitly needed I guess, but that doesn't seem like too big of a deal to me to simplify the code here for flexibility...

@lgolston
Copy link
Contributor

Thanks for identifying that @lgolston. Rather than trying to special-case the various tile styles, I think it might be easier to just go straight to RGBA for all of Stadia so we can also accommodate potential future styles as well without needing to explicitly handle each style's version. This does add an extra alpha channel to the other images when they aren't explicitly needed I guess, but that doesn't seem like too big of a deal to me to simplify the code here for flexibility...

Sounds good! That idea has actually been floated by @pelson before as well, in #762 (comment)_

@lgolston lgolston merged commit 1ad3678 into SciTools:main Oct 20, 2023
22 checks passed
@greglucas greglucas deleted the stadia-api branch July 25, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fetch_tile returns different size images
3 participants