Skip to content

basemaps module

Module for basemaps. Each basemap is defined as item in the basemaps dictionary. For example, to access Google basemaps, use the following:

basemaps['ROADMAP'], basemaps['SATELLITE'], basemaps['HYBRID'].

More WMS basemaps can be found at the following websites:

  1. USGS National Map: https://viewer.nationalmap.gov/services/

  2. MRLC NLCD Land Cover data: https://viewer.nationalmap.gov/services/

  3. FWS NWI Wetlands data: https://www.fws.gov/wetlands/Data/Web-Map-Services.html

get_xyz_dict(free_only=True, _collection=None, _output=None)

Returns a dictionary of xyz services.

Parameters:

Name Type Description Default
free_only bool

Whether to return only free xyz tile services that do not require an access token. Defaults to True.

True

Returns:

Type Description
dict

A dictionary of xyz services.

Source code in geemap/basemaps.py
def get_xyz_dict(free_only=True, _collection=None, _output=None):
    """Returns a dictionary of xyz services.

    Args:
        free_only (bool, optional): Whether to return only free xyz tile services that do not require an access token. Defaults to True.

    Returns:
        dict: A dictionary of xyz services.
    """

    if _collection is None:
        _collection = xyz

    if _output is None:
        _output = {}

    for v in _collection.values():
        if isinstance(v, TileProvider):
            if not (v.requires_token() and free_only):
                _output[v.name] = v
        else:  # it's a Bunch
            get_xyz_dict(free_only, v, _output)

    return collections.OrderedDict(sorted(_output.items()))

search_qms(keywords, limit=10)

Search qms files for keywords. Reference: https://github.com/geopandas/xyzservices/issues/65

Parameters:

Name Type Description Default
keywords str

Keywords to search for.

required
limit int

Number of results to return.

10
Source code in geemap/basemaps.py
def search_qms(keywords, limit=10):
    """Search qms files for keywords. Reference: https://github.com/geopandas/xyzservices/issues/65

    Args:
        keywords (str): Keywords to search for.
        limit (int): Number of results to return.
    """
    QMS_API = "https://qms.nextgis.com/api/v1/geoservices"

    services = requests.get(
        f"{QMS_API}/?search={keywords}&type=tms&epsg=3857&limit={str(limit)}"
    )
    services = services.json()
    if services["count"] == 0:
        return None
    elif services["count"] <= limit:
        return services["results"]
    else:
        return services["results"][:limit]

xyz_to_folium()

Convert xyz tile services to folium tile layers.

Returns:

Type Description
dict

A dictionary of folium tile layers.

Source code in geemap/basemaps.py
def xyz_to_folium():
    """Convert xyz tile services to folium tile layers.

    Returns:
        dict: A dictionary of folium tile layers.
    """
    folium_dict = {}

    for key, tile in xyz_tiles.items():
        folium_dict[key] = folium.TileLayer(
            tiles=tile["url"],
            attr=tile["attribution"],
            name=tile["name"],
            overlay=True,
            control=True,
            max_zoom=22,
        )

    for key, tile in wms_tiles.items():
        folium_dict[key] = folium.WmsTileLayer(
            url=tile["url"],
            layers=tile["layers"],
            name=tile["name"],
            attr=tile["attribution"],
            fmt=tile["format"],
            transparent=tile["transparent"],
            overlay=True,
            control=True,
        )

    for item in get_xyz_dict().values():
        folium_dict[item.name] = folium.TileLayer(
            tiles=item.build_url(),
            attr=item.attribution,
            name=item.name,
            max_zoom=item.get("max_zoom", 22),
            overlay=True,
            control=True,
        )

    if os.environ.get("PLANET_API_KEY") is not None:

        planet_dict = planet_tiles(tile_format="folium")
        folium_dict.update(planet_dict)

    return folium_dict

xyz_to_heremap()

Convert xyz tile services to hermap tile layers.

Returns:

Type Description
dict

A dictionary of heremap tile layers.

Source code in geemap/basemaps.py
def xyz_to_heremap():
    """Convert xyz tile services to hermap tile layers.

    Returns:
        dict: A dictionary of heremap tile layers.
    """

    try:
        import here_map_widget
    except ImportError:
        raise ImportError(
            'This module requires the hermap package. Please install it using "pip install here-map-widget-for-jupyter".'
        )

    # Built-in heremap tile services.
    here_tiles = {
        "HERE_RASTER_NORMAL_MAP": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.map
        ),
        "HERE_RASTER_NORMAL_BASE": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.base
        ),
        "HERE_RASTER_NORMAL_BASE_NIGHT": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.basenight
        ),
        "HERE_RASTER_NORMAL_LABELS": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.labels
        ),
        "HERE_RASTER_NORMAL_TRANSIT": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.transit
        ),
        "HERE_RASTER_NORMAL_XBASE": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.xbase
        ),
        "HERE_RASTER_NORMAL_XBASE_NIGHT": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.normal.xbasenight
        ),
        "HERE_RASTER_SATELLITE_MAP": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.satellite.map
        ),
        "HERE_RASTER_SATELLITE_LABELS": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.satellite.labels
        ),
        "HERE_RASTER_SATELLITE_BASE": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.satellite.base
        ),
        "HERE_RASTER_SATELLITE_XBASE": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.satellite.xbase
        ),
        "HERE_RASTER_TERRAIN_MAP": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.terrain.map
        ),
        "HERE_RASTER_TERRAIN_LABELS": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.terrain.labels
        ),
        "HERE_RASTER_TERRAIN_BASE": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.terrain.base
        ),
        "HERE_RASTER_TERRAIN_XBASE": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.raster.terrain.xbase
        ),
        "HERE_VECTOR_NORMAL_MAP": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.vector.normal.map
        ),
        "HERE_VECTOR_NORMAL_TRUCK": here_map_widget.DefaultLayers(
            layer_name=here_map_widget.DefaultLayerNames.vector.normal.truck
        ),
    }

    heremap_dict = {}

    for key, tile in xyz_tiles.items():
        heremap_dict[key] = here_map_widget.TileLayer(
            provider=here_map_widget.ImageTileProvider(
                url=tile["url"], attribution=tile["attribution"], name=tile["name"]
            )
        )

    for item in get_xyz_dict().values():
        heremap_dict[item.name] = here_map_widget.TileLayer(
            provider=here_map_widget.ImageTileProvider(
                url=item.build_url(),
                attribution=item.attribution,
                name=item.name,
                max_zoom=item.get("max_zoom", 22),
            )
        )

    heremap_dict.update(here_tiles)

    return heremap_dict

xyz_to_leaflet()

Convert xyz tile services to ipyleaflet tile layers.

Returns:

Type Description
dict

A dictionary of ipyleaflet tile layers.

Source code in geemap/basemaps.py
def xyz_to_leaflet():
    """Convert xyz tile services to ipyleaflet tile layers.

    Returns:
        dict: A dictionary of ipyleaflet tile layers.
    """
    leaflet_dict = {}

    for key, tile in xyz_tiles.items():
        name = tile["name"]
        url = tile["url"]
        attribution = tile["attribution"]
        leaflet_dict[key] = ipyleaflet.TileLayer(
            url=url, name=name, attribution=attribution, max_zoom=22
        )

    for key, tile in wms_tiles.items():
        leaflet_dict[key] = ipyleaflet.WMSLayer(
            url=tile["url"],
            layers=tile["layers"],
            name=tile["name"],
            attribution=tile["attribution"],
            format=tile["format"],
            transparent=tile["transparent"],
        )

    for item in get_xyz_dict().values():
        leaflet_dict[item.name] = ipyleaflet.TileLayer(
            url=item.build_url(),
            name=item.name,
            max_zoom=item.get("max_zoom", 22),
            attribution=item.attribution,
        )

    if os.environ.get("PLANET_API_KEY") is not None:

        planet_dict = planet_tiles(tile_format="ipyleaflet")
        leaflet_dict.update(planet_dict)

    return leaflet_dict

xyz_to_plotly()

Convert xyz tile services to plotly tile layers.

Returns:

Type Description
dict

A dictionary of plotly tile layers.

Source code in geemap/basemaps.py
def xyz_to_plotly():
    """Convert xyz tile services to plotly tile layers.

    Returns:
        dict: A dictionary of plotly tile layers.
    """
    plotly_dict = {}

    for key, tile in xyz_tiles.items():
        plotly_dict[key] = {
            "below": "traces",
            "sourcetype": "raster",
            "sourceattribution": tile["attribution"],
            "source": [tile["url"]],
            "name": key,
        }

    for item in get_xyz_dict().values():
        plotly_dict[item.name] = {
            "below": "traces",
            "sourcetype": "raster",
            "sourceattribution": item.attribution,
            "source": [item.build_url()],
            "name": item.name,
        }

    return plotly_dict

xyz_to_pydeck()

Convert xyz tile services to pydeck custom tile layers.

Returns:

Type Description
dict

A dictionary of pydeck tile layers.

Source code in geemap/basemaps.py
def xyz_to_pydeck():
    """Convert xyz tile services to pydeck custom tile layers.

    Returns:
        dict: A dictionary of pydeck tile layers.
    """

    check_package("pydeck", "https://deckgl.readthedocs.io/en/latest/installation.html")
    import pydeck as pdk

    pydeck_dict = {}

    for key, tile in xyz_tiles.items():
        url = tile["url"]
        pydeck_dict[key] = url

    for key, item in get_xyz_dict().items():
        url = item.build_url()
        pydeck_dict[key] = url

        if os.environ.get("PLANET_API_KEY") is not None:

            planet_dict = planet_tiles(tile_format="ipyleaflet")
            for id_, tile in planet_dict.items():
                pydeck_dict[id_] = tile.url

    pdk.settings.custom_libraries = [
        {
            "libraryName": "MyTileLayerLibrary",
            "resourceUri": "https://cdn.jsdelivr.net/gh/giswqs/pydeck_myTileLayer@master/dist/bundle.js",
        }
    ]

    for key in pydeck_dict:
        pydeck_dict[key] = pdk.Layer("MyTileLayer", pydeck_dict[key], key)

    return pydeck_dict

Last update: 2022-09-24
Back to top