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:
-
USGS National Map: https://viewer.nationalmap.gov/services/
-
MRLC NLCD Land Cover data: https://viewer.nationalmap.gov/services/
-
FWS NWI Wetlands data: https://www.fws.gov/wetlands/Data/Web-Map-Services.html
get_xyz_dict(free_only=True, france=False)
¶
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 |
france |
bool |
Whether include Geoportail France basemaps. Defaults to False. |
False |
Returns:
Type | Description |
---|---|
dict |
A dictionary of xyz services. |
Source code in geemap/basemaps.py
def get_xyz_dict(free_only=True, france=False):
"""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.
france (bool, optional): Whether include Geoportail France basemaps. Defaults to False.
Returns:
dict: A dictionary of xyz services.
"""
xyz_dict_tmp = {}
for item in xyz.values():
try:
name = item["name"]
tile = _unpack_sub_parameters(xyz, name)
if _unpack_sub_parameters(xyz, name).requires_token():
if free_only:
pass
else:
xyz_dict_tmp[name] = tile
else:
xyz_dict_tmp[name] = tile
tile["type"] = "xyz"
except Exception:
for sub_item in item:
name = item[sub_item]["name"]
tile = _unpack_sub_parameters(xyz, name)
if _unpack_sub_parameters(xyz, name).requires_token():
if free_only:
pass
else:
xyz_dict_tmp[name] = tile
else:
xyz_dict_tmp[name] = tile
tile["type"] = "xyz"
xyz_dict = {}
if france:
xyz_dict = xyz_dict_tmp
else:
for key in xyz_dict_tmp:
if "France" not in key:
xyz_dict[key] = xyz_dict_tmp[key]
xyz_dict = collections.OrderedDict(sorted(xyz_dict.items()))
return xyz_dict
qms_to_geemap(service_id)
¶
Convert a qms service to an ipyleaflet tile layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_id |
str |
Service ID. |
required |
Returns:
Type | Description |
---|---|
ipyleaflet.TileLayer |
An ipyleaflet tile layer. |
Source code in geemap/basemaps.py
def qms_to_geemap(service_id):
"""Convert a qms service to an ipyleaflet tile layer.
Args:
service_id (str): Service ID.
Returns:
ipyleaflet.TileLayer: An ipyleaflet tile layer.
"""
service_details = get_qms(service_id)
name = service_details["name"]
url = service_details["url"]
attribution = service_details["copyright_text"]
layer = ipyleaflet.TileLayer(url=url, name=name, attribution=attribution)
return layer
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_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 in xyz_tiles:
xyz_tiles[key]["type"] = "xyz"
name = xyz_tiles[key]["name"]
leaflet_dict[key] = xyz_tiles[key]
for key in wms_tiles:
wms_tiles[key]["type"] = "wms"
name = wms_tiles[key]["name"]
leaflet_dict[key] = wms_tiles[key]
xyz_dict = get_xyz_dict()
for item in xyz_dict:
name = xyz_dict[item].name
xyz_dict[item]["url"] = xyz_dict[item].build_url()
leaflet_dict[name] = xyz_dict[item]
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
Created: 2020-08-22