Git Product home page Git Product logo

Comments (9)

binste avatar binste commented on May 19, 2024 1

Interesting! OpenStreetMap.BlackAndWhite seems to have been deprecated leaflet-extras/leaflet-providers#316 and also does not show up for me in a notebook but the others are weird. I've opened vega/vl-convert#162 to investigate this further, thanks again! Hope the "Save as PNG" context menu works for you in the meantime.

from altair_tiles.

binste avatar binste commented on May 19, 2024

Thanks for the feedback Till! Do you have a minimal reproducible example I could test against? It works for me using the following code with Altair 5.3.0, altair_tiles 0.3.0, vl-convert-python 1.3.0:

import altair as alt
import altair_tiles as til
import geopandas as gpd

gdf_ne = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip")  # zipped shapefile
extent_roi = gdf_ne.loc[gdf_ne["CONTINENT"] == "Africa", ["CONTINENT", "geometry"]]

chart = (
    alt.Chart(extent_roi)
    .mark_geoshape(fillOpacity=0.1, stroke="green", strokeWidth=2)
    .project(type="mercator")
)
chart = til.add_tiles(chart).properties(width=600, height=400)
chart.save("chart.png")

By the way, if you want to increase the resolution of the PNG you get from the context menu, you can run alt.renderers.set_embed_options(scaleFactor=3) and then display the chart again (rerun the notebook cell).

from altair_tiles.

tillnagel avatar tillnagel commented on May 19, 2024

Thanks for the quick response! It seems this does not work only if a provider is specified.

Works for me as well with your code from above. The following however creates a chart.png without a base map.

import altair as alt
import altair_tiles as til
import geopandas as gpd

gdf_ne = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip")  # zipped shapefile
extent_roi = gdf_ne.loc[gdf_ne["CONTINENT"] == "Africa", ["CONTINENT", "geometry"]]

chart = (
    alt.Chart(extent_roi)
    .mark_geoshape(fillOpacity=0.1, stroke="green", strokeWidth=2)
    .project(type="mercator")
)
chart = til.add_tiles(chart, provider=til.providers.BaseMapDE.Grey).properties(width=600, height=400)
chart.save("chart.png")

from altair_tiles.

tillnagel avatar tillnagel commented on May 19, 2024

And thanks for the tip @binste to set the scaleFactor. Works like a charm.

from altair_tiles.

binste avatar binste commented on May 19, 2024

I think we're getting closer to the issue. Can you try it with a different provider such as OpenStreetMap.HOT? At least in this example, the basemap is also not included when displaying the chart. I think it's because BaseMapDE is just for Germany according to https://gdz.bkg.bund.de/index.php/default/gdz-basemapde-vektor-gdz-basemapde-vektor.html.

Some context to this: BaseMapDE will only work if we have a map of Germany. In addition, altair_tiles needs to ensure that only valid tiles are being loaded from the server, else no tiles at all will show up. This is happening at https://github.com/vega/altair_tiles/blob/main/altair_tiles/__init__.py#L281 in the code. However, I think right now it will even fail then, because the package xyzservices usually provides a bounds attribute on providers if they do not cover the whole world. However, BaseMapDE is missing that attribute.

Do you know by any chance which bounds are valid for BaseMapDE? I can't find anything on their website. We could then open an issue in the repo of xyzservices to include it.

from altair_tiles.

tillnagel avatar tillnagel commented on May 19, 2024

Weird, some work, some do not.

It does not seem to be related to the bounds (my actual map is in Germany; just for the MRE I used your example).

OpenStreetMap.HOT works
Esri.WorldGrayCanvas fails
BaseMapDE.Grey fails
OpenStreetMap.BlackAndWhite fails
OpenStreetMap.Mapnik works

from altair_tiles.

jonmmease avatar jonmmease commented on May 19, 2024

This has been fixed in vl-convert-python 1.4.0. The issue was that vl-convert was failing to handle tile providers that don't include file extensions in the url.

So https://tile.openstreetmap.org/{z}/{x}/{y}.png was working, but not https://server.arcgisonline.com/ArcGIS/rest/services/{variant}/MapServer/tile/{z}/{y}/{x}

See vega/vl-convert#163

from altair_tiles.

binste avatar binste commented on May 19, 2024

Thank you very much @jonmmease!! Really appreciate it.

@tillnagel could you check if this solves the issue you had with BaseMapDE.Grey?

from altair_tiles.

tillnagel avatar tillnagel commented on May 19, 2024

Works now. Great work @jonmmease! Thanks for the support and this great lib @binste!

from altair_tiles.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.