holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
597 stars 77 forks source link

Add geoviews offline features and tiles docs #649

Closed ahuang11 closed 1 year ago

ahuang11 commented 1 year ago

Directly based on https://discourse.pangeo.io/t/geoviews-offline/3487/2 Partially based on https://discourse.holoviz.org/t/using-geoviews-tile-sources-offline/4859/5

Planning to do tiles soon.

hoxbro commented 1 year ago

Maybe think about if we should move this information into another place than the front page.

ahuang11 commented 1 year ago

Yeah I was uncertain on whether I should put this on front page or one of the gallery items because of

1. Create a new cartopy environment (or use an existing one)::

    conda create -n cartopy_env python=3.10

2. Install the required packages::

    conda install -c conda-forge geoviews cartopy cartopy_offlinedata
hoxbro commented 1 year ago

I think this should have a new page. I would build it up like a how-to, e.g, How to use tiles offline and put it in the user guide for now.

ahuang11 commented 1 year ago
image image
hoxbro commented 1 year ago

I will look into this more tomorrow, but I think cache_tiles could be added directly to geoviews.util.

ahuang11 commented 1 year ago

Yeah that sounds like a good idea.

I'm not exactly sure how WMTS works under the hood; does it use cartopy or bokeh to fetch the tiles underneath?


class WMTS(_GeoFeature):
    """
    The WMTS Element represents a Web Map Tile Service specified as a
    URL containing {x}, {y}, and {z} templating variables, e.g.:

    https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}@2x.png
    """

    crs = param.ClassSelector(default=ccrs.GOOGLE_MERCATOR, class_=ccrs.CRS, doc="""
        Cartopy coordinate-reference-system specifying the
        coordinate system of the data. Inferred automatically
        when _Element wraps cartopy Feature object.""")

    group = param.String(default='WMTS')

    layer = param.String(doc="The layer on the tile service")

    def __init__(self, data, kdims=None, vdims=None, **params):
        if ((MercatorTileSource and isinstance(data, MercatorTileSource)) or
            (GoogleTiles and isinstance(data, GoogleTiles))):
            data = data.url
        elif WebMapTileService and isinstance(data, WebMapTileService):
            pass
        elif not isinstance(data, str):
            raise TypeError(
                f'{type(self).__name__} data should be a tile service '
                f'URL not a {type(data).__name__} type.'
            )
        super().__init__(data, kdims=kdims, vdims=vdims, **params)

    def __call__(self, *args, **kwargs):
        return self.opts(*args, **kwargs)
ahuang11 commented 1 year ago

But yeah, maybe this caching thing could be used to fix https://github.com/holoviz/geoviews/issues/650

ahuang11 commented 1 year ago

Any other thoughts on this PR?

hoxbro commented 1 year ago

In the future, we will need to convert this to real markdown files, as we have done with Panel.

I just tried, and this is already possible. So the notebooks can be converted to Markdown files.

ahuang11 commented 1 year ago

How do I convert the notebooks to Markdown files?

hoxbro commented 1 year ago

I just copied the content to a new markdown file.

ahuang11 commented 1 year ago

Thanks for reviewing!