contextily
contextily copied to clipboard
Allow RGBA tiles for "*OnlyLabels" maps
Currently, downloaded tiles are implicitely converted to RGB images. https://github.com/geopandas/contextily/blob/37ac810a6f159be64855585c6fcab63a6f681673/contextily/tile.py#L305
However, since leaflet-providers supports maps with decomposed map and overlay labels, the maps with only labels need to be opened as RGBA images. PIL is also complaining about RGB casting on palette images.
.../lib/python3.6/site-packages/PIL/Image.py:960: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
Minimal working example to reproduce the behavior:
import geopandas
import matplotlib.pyplot as plt
df = geopandas.read_file(geopandas.datasets.get_path('nybb'))
df = df.to_crs(epsg=3857)
ax = df.plot(figsize=(10, 10), alpha=0.5, edgecolor='k')
provider = contextily.providers.CartoDB.DarkMatterNoLabels
contextily.add_basemap(
ax=ax,
source=provider,
)
provider = contextily.providers.CartoDB.DarkMatterOnlyLabels
contextily.add_basemap(
ax=ax,
source=provider,
zorder=10,
alpha=0.5 # this makes the background map and polygons visible
)
plt.show()
@razorx89 thanks for opening the issue! There is currently an open PR that I think does exactly what you are suggesting: https://github.com/geopandas/contextily/pull/114
@razorx89 thanks for opening the issue! There is currently an open PR that I think does exactly what you are suggesting: #114
Yep, #114 fixes this. You also wouldn't need to have alpha=0.5
on the labels-only layer.