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

Transparencey issue using hybrid style from GoogleTiles #762

Open
mattijn opened this issue Apr 21, 2016 · 7 comments
Open

Transparencey issue using hybrid style from GoogleTiles #762

mattijn opened this issue Apr 21, 2016 · 7 comments

Comments

@mattijn
Copy link

mattijn commented Apr 21, 2016

In the code comment is mentioned that it is possible to get hybrid style form google by using only_streets and satellite

# Only streets are partly transparent tiles that can be overlayed over
# the satellite map to create the known hybrid style from google.

But by using this code:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io import img_tiles
%matplotlib inline

tiles_sat = img_tiles.GoogleTiles(style='satellite')
tiles_str = img_tiles.GoogleTiles(style='only_streets')
web_merc = img_tiles.GoogleTiles().crs
img_extent = (31, 35.5, 34, 36)

ax = plt.axes(projection=web_merc)
plt.title('Cyprus')
ax.set_extent([31, 35.5, 34, 36], ccrs.Geodetic())
ax.coastlines(resolution='10m')
ax.add_image(tiles_sat, 8)
ax.add_image(tiles_str, 8)

plt.show()

untitled

It won't give a transparent, but one with a black background.
Am I missing something?

@QuLogic
Copy link
Member

QuLogic commented Apr 21, 2016

Probably this warning that shows up indicates what needs to be fixed here:

/usr/lib64/python3.4/site-packages/PIL/Image.py:861: UserWarning: Palette images with Transparency   expressed in bytes should be converted to RGBA images
  'to RGBA images')

@QuLogic
Copy link
Member

QuLogic commented Apr 21, 2016

Actually, that's a pretty good hint... Use img_tiles.GoogleTiles(desired_tile_form='RGBA', style='only_streets') and it works correctly.

Not so sure if this qualifies as a bug so much as maybe an enhancement that could be made to automatically pick this setting?

@mattijn
Copy link
Author

mattijn commented Apr 21, 2016

Ah, Yes! That makes sense, or maybe a comment in the function description would do.

@pelson
Copy link
Member

pelson commented Apr 21, 2016

Ah, Yes! That makes sense, or maybe a comment in the function description would do.

Would you be interested in contributing @mattijn? Docs are always a healthy thing to improve!

@pelson
Copy link
Member

pelson commented Jan 10, 2019

Action: change the default from RGB to RGBA. The implication is on performance only, AFAICS.

@enorazza
Copy link

enorazza commented Jun 3, 2019

This is also important for the Stamen class.
Try: cimgt.Stamen(style='toner-labels')
Output has black background :(
I haven't understood if there is a workaround for this.. where should I put the "desired_tile_form='RGBA'" parameter?

@enorazza
Copy link

enorazza commented Jun 3, 2019

Found the workaround!
This wasn't working: labels = cimgt.Stamen(style='toner-labels', desired_tile_form='RGBA')
But this does: labels = cimgt.GoogleTiles(url="http://tile.stamen.com/toner-labels/{z}/{x}/{y}.png", desired_tile_form='RGBA')
This needs to be added too: ax1.background_patch.set_visible(False)
After this: ax1 = plt.axes([0, 0, 1, 1], projection=labels.crs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants