bokehmap module¶
leafmap.bokehmap
¶
Map
¶
add_basemap(basemap='OpenStreetMap', retina=True, **kwargs)
¶
Adds a basemap to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basemap
|
str
|
Can be one of string from basemaps. Defaults to 'OpenStreetMap'. |
'OpenStreetMap'
|
retina
|
bool
|
Whether to use retina tiles. Defaults to True. |
True
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.add_tile() function, such as alpha, visible, etc. |
{}
|
add_cog_layer(url, attribution='', bands=None, titiler_endpoint=None, cog_args={}, fit_bounds=True, **kwargs)
¶
Adds a COG TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the COG tile layer. |
required |
attribution
|
str
|
The attribution to use. Defaults to ''. |
''
|
bands
|
list
|
A list of bands to use for the layer. Defaults to None. |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://titiler.opengeos.org". |
None
|
cog_args
|
dict
|
Arbitrary keyword arguments, including bidx, expression, nodata, unscale, resampling, rescale,
color_formula, colormap, colormap_name, return_mask. See https://developmentseed.org/titiler/endpoints/cog/
and https://cogeotiff.github.io/rio-tiler/colormap/. To select a certain bands, use bidx=[1, 2, 3].
apply a rescaling to multiple bands, use something like |
{}
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.add_tile() function, such as alpha, visible, etc. |
{}
|
add_gdf(gdf, to_crs='epsg:3857', tooltips=None, fit_bounds=True, **kwargs)
¶
Adds a GeoDataFrame to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
The GeoDataFrame to add to the map. |
required |
to_crs
|
str
|
The CRS to use for the GeoDataFrame. Defaults to "epsg:3857". |
'epsg:3857'
|
tooltips
|
list
|
A list of column names to use for tooltips in the form of [(name, @column_name), ...]. Defaults to None, which uses all columns. |
None
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.circle, multi_line, and patches. For more info, see https://docs.bokeh.org/en/latest/docs/reference/plotting/figure.html#bokeh.plotting.figure |
{}
|
add_geojson(filename, encoding='utf-8', read_file_args={}, to_crs='epsg:3857', tooltips=None, fit_bounds=True, **kwargs)
¶
Adds a GeoJSON file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the GeoJSON file. Can be a local file or a URL. |
required |
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
read_file_args
|
Dict
|
A dictionary of arguments to pass to geopandas.read_file. Defaults to {}. |
{}
|
to_crs
|
str
|
The CRS to use for the GeoDataFrame. Defaults to "epsg:3857". |
'epsg:3857'
|
tooltips
|
list
|
A list of column names to use for tooltips in the form of [(name, @column_name), ...]. Defaults to None, which uses all columns. |
None
|
fit_bounds
|
bool
|
A flag indicating whether to fit the map bounds to the GeoJSON. Defaults to True. |
True
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.circle, multi_line, and patches. For more info, see https://docs.bokeh.org/en/latest/docs/reference/plotting/figure.html#bokeh.plotting.figure |
{}
|
add_raster(source, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, attribution='', fit_bounds=True, layer_name='Local COG', open_args={}, **kwargs)
¶
Add a local raster dataset to the map. If you are using this function in JupyterHub on a remote server (e.g., Binder, Microsoft Planetary Computer) and if the raster does not render properly, try running the following code before calling this function:
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The path to the GeoTIFF file or the URL of the Cloud Optimized GeoTIFF. |
required |
indexes
|
int
|
The band(s) to use. Band indexing starts at 1. Defaults to None. |
None
|
colormap
|
str
|
The name of the colormap from |
None
|
vmin
|
float
|
The minimum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
nodata
|
float
|
The value from the band to use to interpret as not valid data. Defaults to None. |
None
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file. Defaults to None. |
''
|
layer_name
|
str
|
The layer name to use. Defaults to 'Local COG'. |
'Local COG'
|
fit_bounds
|
bool
|
Whether to fit the map bounds to the raster bounds. Defaults to True. |
True
|
open_args
|
dict
|
Arbitrary keyword arguments for get_local_tile_layer(). Defaults to {}. |
{}
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.add_tile() function, such as alpha, visible, etc. |
{}
|
add_shp(filename, encoding='utf-8', read_file_args={}, to_crs='epsg:3857', tooltips=None, fit_bounds=True, **kwargs)
¶
Adds a shapefile to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the shapefile. |
required |
encoding
|
str
|
The encoding of the shapefile. Defaults to "utf-8". |
'utf-8'
|
read_file_args
|
dict
|
A dictionary of arguments to pass to geopandas.read_file. Defaults to {}. |
{}
|
to_crs
|
str
|
The CRS to use for the GeoDataFrame. Defaults to "epsg:3857". |
'epsg:3857'
|
tooltips
|
list
|
A list of column names to use for tooltips in the form of [(name, @column_name), ...]. Defaults to None, which uses all columns. |
None
|
fit_bounds
|
bool
|
A flag indicating whether to fit the map bounds to the shapefile. Defaults to True. |
True
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.circle, multi_line, and patches. For more info, see https://docs.bokeh.org/en/latest/docs/reference/plotting/figure.html#bokeh.plotting.figure |
{}
|
add_stac_layer(url, collection=None, item=None, assets=None, bands=None, titiler_endpoint=None, attribution='', fit_bounds=True, open_args={}, **kwargs)
¶
Adds a STAC TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a STAC item, e.g., https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json |
required |
collection
|
str | Optional
|
The Microsoft Planetary Computer STAC collection ID, e.g., landsat-8-c2-l2. |
None
|
item
|
str
|
The Microsoft Planetary Computer STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1. |
None
|
assets
|
str | list
|
The Microsoft Planetary Computer STAC asset ID, e.g., ["SR_B7", "SR_B5", "SR_B4"]. |
None
|
bands
|
list
|
A list of band names, e.g., ["SR_B7", "SR_B5", "SR_B4"] |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint, e.g., "https://titiler.opengeos.org", "https://planetarycomputer.microsoft.com/api/data/v1", "planetary-computer", "pc". Defaults to None. |
None
|
attribution
|
str
|
The attribution to use. Defaults to ''. |
''
|
fit_bounds
|
bool
|
Whether to fit the map bounds to the raster bounds. Defaults to True. |
True
|
open_args
|
Dict
|
Arbitrary keyword arguments for get_local_tile_layer(). Defaults to {}. |
{}
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.add_tile() function, such as alpha, visible, etc. |
{}
|
add_tile(tile, **kwargs)
¶
Adds a tile to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
WMTSTileSource
|
A bokeh tile. |
required |
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.add_tile() function, such as alpha, visible, etc. |
{}
|
add_vector(filename, encoding='utf-8', read_file_args={}, to_crs='epsg:3857', tooltips=None, fit_bounds=True, **kwargs)
¶
Adds a vector dataset to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The path to the vector dataset. Can be a local file or a URL. |
required |
encoding
|
str
|
The encoding of the vector dataset. Defaults to "utf-8". |
'utf-8'
|
read_file_args
|
Dict
|
A dictionary of arguments to pass to geopandas.read_file. Defaults to {}. |
{}
|
to_crs
|
str
|
The CRS to use for the GeoDataFrame. Defaults to "epsg:3857". |
'epsg:3857'
|
tooltips
|
list
|
A list of column names to use for tooltips in the form of [(name, @column_name), ...]. Defaults to None, which uses all columns. |
None
|
fit_bounds
|
bool
|
A flag indicating whether to fit the map bounds to the vector dataset. Defaults to True. |
True
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.circle, multi_line, and patches. For more info, see https://docs.bokeh.org/en/latest/docs/reference/plotting/figure.html#bokeh.plotting.figure |
{}
|
fit_bounds(bounds)
¶
Fits the map to the specified bounds in the form of [xmin, ymin, xmax, ymax].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list
|
A list of bounds in the form of [xmin, ymin, xmax, ymax]. |
required |
to_html(filename=None, title=None, **kwargs)
¶
Converts the map to HTML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename to save the HTML to. Defaults to None. |
None
|
title
|
str
|
The title to use for the HTML. Defaults to None. |
None
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.figure.save(). |
{}
|
to_streamlit(width=800, height=600, use_container_width=True, **kwargs)
¶
Displays the map in a Streamlit app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The width of the map. Defaults to 800. |
800
|
height
|
int
|
The height of the map. Defaults to 600. |
600
|
use_container_width
|
bool
|
A flag indicating whether to use the full width of the container. Defaults to True. |
True
|
**kwargs
|
Any
|
Arbitrary keyword arguments for bokeh.plotting.show(). |
{}
|