deckgl module¶
leafmap.deckgl
¶
Map
¶
Bases: Map
The Map class inherits lonboard.Map.
__init__(center=(20, 0), zoom=1.2, height=600, layers=[], show_tooltip=True, view_state={}, **kwargs)
¶
Initialize a Map object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
tuple
|
Center of the map in the format of (lat, lon). Defaults to (20, 0). |
(20, 0)
|
zoom
|
float
|
The map zoom level. Defaults to 1.2. |
1.2
|
height
|
int
|
Height of the map. Defaults to 600. |
600
|
layers
|
list
|
List of additional layers to add to the map. Defaults to []. |
[]
|
show_tooltip
|
bool
|
Flag to show tooltips on the map. Defaults to True. |
True
|
view_state
|
dict
|
The view state of the map. Defaults to {}. |
{}
|
**kwargs
|
Any
|
Additional keyword arguments to pass to lonboard.Map. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_basemap(basemap='HYBRID', visible=True, **kwargs)
¶
Adds a basemap to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basemap
|
str
|
Can be one of string from basemaps. Defaults to 'HYBRID'. |
'HYBRID'
|
visible
|
bool
|
Whether the basemap is visible or not. Defaults to True. |
True
|
**kwargs
|
Any
|
Keyword arguments for the TileLayer. |
{}
|
add_gdf(gdf, zoom_to_layer=True, pickable=True, color_column=None, color_scheme='Quantiles', color_map=None, color_k=5, color_args={}, alpha=1.0, rescale=True, zoom=10.0, **kwargs)
¶
Adds a GeoPandas GeoDataFrame to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoPandas GeoDataFrame with geometry column. |
required |
zoom_to_layer
|
bool
|
Flag to zoom to the added layer. Defaults to True. |
True
|
pickable
|
bool
|
Flag to enable picking on the added layer. Defaults to True. |
True
|
color_column
|
Optional[str]
|
The column to be used for color encoding. Defaults to None. |
None
|
color_map
|
Optional[Union[str, Dict]]
|
The color map to use for color encoding. It can be a string or a dictionary. Defaults to None. |
None
|
color_scheme
|
Optional[str]
|
The color scheme to use for color encoding. Defaults to "Quantiles". Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', 'UserDefined'). Arguments can be passed in classification_kwds. |
'Quantiles'
|
color_k
|
Optional[int]
|
The number of classes to use for color encoding. Defaults to 5. |
5
|
color_args
|
dict
|
Additional keyword arguments that will be passed to assign_continuous_colors(). Defaults to {}. |
{}
|
zoom
|
Optional[float]
|
The zoom level to zoom to. Defaults to 10.0. |
10.0
|
**kwargs
|
Any
|
Additional keyword arguments that will be passed to lonboard.Layer.from_geopandas() |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_layer(layer, zoom_to_layer=True, pickable=True, **kwargs)
¶
Adds a layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
Any
|
A lonboard layer object. |
required |
zoom_to_layer
|
bool
|
Whether to zoom to the layer extent. Defaults to True. |
True
|
pickable
|
bool
|
Flag to enable picking on the added layer if it's a vector layer. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments that will be passed to the vector layer if it's a vector layer. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_raster(source, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, tile_size=256, attribution=None, layer_name='Raster', zoom_to_layer=True, visible=True, opacity=1.0, array_args={}, client_args={'cors_all': True}, **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 installing jupyter-server-proxy using pip install jupyter-server-proxy,
then running the following code before calling this function. For more info, see https://bit.ly/3JbmF93.
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 palette when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the palette 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. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to 'Raster'. |
'Raster'
|
zoom_to_layer
|
bool
|
Whether to zoom to the extent of the layer. Defaults to True. |
True
|
visible
|
bool
|
Whether the layer is visible. Defaults to True. |
True
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
array_args
|
dict
|
Additional arguments to pass to |
{}
|
client_args
|
dict
|
Additional arguments to pass to localtileserver.TileClient. Defaults to { "cors_all": False }. |
{'cors_all': True}
|
add_tile_layer(url, opacity=1.0, visible=True, tile_size=256, **kwargs)
¶
Adds a TileLayer to the map.
This method adds a TileLayer to the map. The TileLayer is created from the specified URL, and it is added to the map with the specified name, attribution, visibility, and tile size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the tile layer. |
required |
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
visible
|
bool
|
Whether the layer should be visible by default. Defaults to True. |
True
|
tile_size
|
int
|
The size of the tiles in the layer. Defaults to 256. |
256
|
**kwargs
|
Any
|
Additional keyword arguments that are passed to the lonboard.BitmapTileLayer class. See https://developmentseed.org/lonboard/latest/api/layers/bitmap-tile-layer/#lonboard.BitmapTileLayer. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
add_vector(vector, zoom_to_layer=True, pickable=True, color_column=None, color_scheme='Quantiles', color_map=None, color_k=5, color_args={}, open_args={}, **kwargs)
¶
Adds a vector layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
Union[str, GeoDataFrame]
|
The file path or URL to the vector data, or a GeoDataFrame. |
required |
zoom_to_layer
|
bool
|
Flag to zoom to the added layer. Defaults to True. |
True
|
pickable
|
bool
|
Flag to enable picking on the added layer. Defaults to True. |
True
|
color_column
|
Optional[str]
|
The column to be used for color encoding. Defaults to None. |
None
|
color_map
|
Optional[Union[str, Dict]]
|
The color map to use for color encoding. It can be a string or a dictionary. Defaults to None. |
None
|
color_scheme
|
Optional[str]
|
The color scheme to use for color encoding. Defaults to "Quantiles". Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', 'UserDefined'). Arguments can be passed in classification_kwds. |
'Quantiles'
|
color_k
|
Optional[int]
|
The number of classes to use for color encoding. Defaults to 5. |
5
|
color_args
|
dict
|
Additional keyword arguments that will be passed to assign_continuous_colors(). Defaults to {}. |
{}
|
open_args
|
dict
|
Additional keyword arguments that will be passed to geopandas.read_file(). Defaults to {}. |
{}
|
**kwargs
|
Any
|
Additional keyword arguments that will be passed to lonboard.Layer.from_geopandas() |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
to_html(filename=None)
¶
Saves the map as an HTML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Optional[str]
|
The output file path to the HTML file. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
None
|
The HTML content if filename is None. |
to_streamlit(width=None, height=600, scrolling=False, **kwargs)
¶
Renders deckgl.Mapin a Streamlit app. This method is a static Streamlit Component, meaning, no information is passed back from Leaflet on browser interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the map. Defaults to None. |
None
|
height
|
int
|
Height of the map. Defaults to 600. |
600
|
scrolling
|
bool
|
Whether to allow the map to scroll. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
streamlit.components: components.html object. |
apply_categorical_cmap(values, cmap, alpha=None, **kwargs)
¶
Apply a categorical colormap to a set of values.
This function applies a specified categorical colormap to the input values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
The input values to which the colormap will be applied. |
required |
cmap
|
str or Colormap
|
The colormap to apply. Can be a string name of a matplotlib colormap or a Colormap object. |
required |
alpha
|
float
|
The alpha transparency to apply to the colormap. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the colormap function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
array |
Any
|
The colors mapped to the input values. |
apply_continuous_cmap(values, cmap, alpha=None, rescale=True, **kwargs)
¶
Apply a continuous colormap to a set of values.
This function rescales the input values to the range [0, 1] if rescale is True,
and then applies the specified colormap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
The input values to which the colormap will be applied. |
required |
cmap
|
str or Colormap
|
The colormap to apply. Can be a string name of a matplotlib colormap or a Colormap object. |
required |
alpha
|
float
|
The alpha transparency to apply to the colormap. Defaults to None. |
None
|
rescale
|
bool
|
If True, rescales the input values to the range [0, 1]. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the colormap function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
array |
Any
|
The colors mapped to the input values. |