ecoscope.mapping#
Submodules#
Package Contents#
- class ecoscope.mapping.EcoMap(static=False, default_widgets=True, *args, **kwargs)[source]#
Bases:
EcoMapMixin
,lonboard.Map
The top-level class used to display a map in a Jupyter Widget.
Example:
```py import geopandas as gpd from lonboard import Map, ScatterplotLayer, SolidPolygonLayer
# A GeoDataFrame with Point geometries point_gdf = gpd.GeoDataFrame() point_layer = ScatterplotLayer.from_geopandas(
point_gdf, get_fill_color=[255, 0, 0],
)
# A GeoDataFrame with Polygon geometries polygon_gdf = gpd.GeoDataFrame() polygon_layer = SolidPolygonLayer.from_geopandas(
gdf, get_fill_color=[255, 0, 0],
)
m = Map([point_layer, polygon_layer]) ```
- add_layer(layer, zoom=False)[source]#
Adds a layer or list of layers to the map :param layer: :type layer: lonboard.BaseLayer or list[lonboard.BaseLayer] :param zoom: Whether to zoom the map to the new layer :type zoom: bool
- Parameters:
layer (Union[lonboard._layer.BaseLayer, List[lonboard._layer.BaseLayer]])
zoom (bool)
- add_widget(widget)[source]#
Adds a deck widget to the map :param widget: :type widget: lonboard.BaseDeckWidget or list[lonboard.BaseDeckWidget]
- Parameters:
widget (lonboard._deck_widget.BaseDeckWidget)
- static layers_from_gdf(gdf, **kwargs)[source]#
Creates map layers from the provided gdf, returns multiple layers when geometry is mixed Style kwargs are provided to all created layers :param gdf: The data to be cleaned :type gdf: gpd.GeoDataFrame :param kwargs: :type kwargs: Additional kwargs passed to lonboard
- Parameters:
gdf (geopandas.GeoDataFrame)
- Return type:
List[Union[lonboard._layer.ScatterplotLayer, lonboard._layer.PathLayer, lonboard._layer.PolygonLayer]]
- static _clean_gdf(gdf)[source]#
Cleans a gdf for use in a map layer, ensures EPSG:4326 and removes any empty geometry :param gdf: The data to be cleaned :type gdf: gpd.GeoDataFrame
- Parameters:
gdf (geopandas.GeoDataFrame)
- Return type:
geopandas.geodataframe
- static polyline_layer(gdf, color_column=None, **kwargs)[source]#
Creates a polyline layer to add to a map :param gdf: The data used to create the visualization layer :type gdf: gpd.GeoDataFrame :param kwargs: Additional kwargs passed to lonboard.PathLayer:
- Parameters:
gdf (geopandas.GeoDataFrame)
color_column (str)
- Return type:
lonboard._layer.PathLayer
- static polygon_layer(gdf, fill_color_column=None, line_color_column=None, **kwargs)[source]#
Creates a polygon layer to add to a map :param gdf: The data used to create the visualization layer :type gdf: gpd.GeoDataFrame :param kwargs: Additional kwargs passed to lonboard.PathLayer:
- Parameters:
gdf (geopandas.GeoDataFrame)
fill_color_column (str)
line_color_column (str)
- Return type:
lonboard._layer.PolygonLayer
- static point_layer(gdf, fill_color_column=None, line_color_column=None, **kwargs)[source]#
Creates a polygon layer to add to a map :param gdf: The data used to create the visualization layer :type gdf: gpd.GeoDataFrame :param kwargs: Additional kwargs passed to lonboard.ScatterplotLayer:
- Parameters:
gdf (geopandas.GeoDataFrame)
fill_color_column (str)
line_color_column (str)
- Return type:
lonboard._layer.ScatterplotLayer
- add_legend(labels, colors, **kwargs)[source]#
Adds a legend to the map :param placement: One of “top-left”, “top-right”, “bottom-left”, “bottom-right” or “fill”
Where to place the widget within the map
- Parameters:
title (str) – A title displayed on the widget
labels (list or pd.Series) – A list or series of labels
colors (list or pd.Series) – A list or series of colors as string hex values or RGBA color tuples
style (dict) – Additional style params
- add_north_arrow(**kwargs)[source]#
Adds a north arrow to the map :param placement: Where to place the widget within the map :type placement: str, one of “top-left”, “top-right”, “bottom-left”, “bottom-right” or “fill” :param style: Additional style params :type style: dict
- add_scale_bar(**kwargs)[source]#
Adds a scale bar to the map :param placement: Where to place the widget within the map :type placement: str, one of “top-left”, “top-right”, “bottom-left”, “bottom-right” or “fill” :param use_imperial: If true, show scale in miles/ft, rather than m/km :type use_imperial: bool :param style: Additional style params :type style: dict
- add_title(title, **kwargs)[source]#
Adds a title to the map :param title: The map title :type title: str :param style: Additional style params :type style: dict
- Parameters:
title (str)
- add_save_image(**kwargs)[source]#
Adds a button to save the map as a png :param placement: Where to place the widget within the map :type placement: str, one of “top-left”, “top-right”, “bottom-left”, “bottom-right” or “fill” :param style: Additional style params :type style: dict
- static ee_layer(ee_object, visualization_params, **kwargs)[source]#
Creates a layer from the provided Earth Engine. If an EE.Image/EE.ImageCollection or EE.FeatureCollection is provided, this results in a BitmapTileLayer being added
For EE.Geometry objects, a list of ScatterplotLayer,PathLayer and PolygonLayer will be added based on the geometry itself (see add_gdf)
- Parameters:
ee_object (ee.Image, ee.ImageCollection, ee.Geometry, ee.FeatureCollection]) – The ee object to represent as a layer
visualization_params (dict) – Visualization params passed to EarthEngine
kwargs – Additional params passed to either lonboard.BitmapTileLayer or add_gdf
- zoom_to_bounds(feat, max_zoom=20)[source]#
Zooms the map to the bounds of a dataframe or layer.
- Parameters:
feat (BaseLayer, List[lonboard.BaseLayer], gpd.GeoDataFrame) – The feature to zoom to
max_zoom (int)
- static geotiff_layer(tiff, cmap=None, opacity=0.7)[source]#
Creates a layer from a given geotiff Note that since deck.gl tiff support is limited, this extracts the CRS/Bounds from the tiff and converts the image data in-memory to PNG
- Parameters:
tiff (str | rio.MemoryFile) – The string path to a tiff on disk or a rio.MemoryFile
cmap (str or matplotlib.colors.Colormap) – The colormap to apply to the raster
opacity (float) – The opacity of the overlay
- static pil_layer(image, bounds, opacity=1)[source]#
Creates layer from a PIL.Image
- Parameters:
image (PIL.Image) – The image to be overlaid
bounds (tuple) – Tuple containing the EPSG:4326 (minx, miny, maxx, maxy) values bounding the given image
opacity (float, optional) – Sets opacity of overlaid image
- static get_named_tile_layer(layer, opacity=1)[source]#
- Parameters:
layer (str)
opacity (float)
- Return type:
lonboard._layer.BitmapTileLayer
- to_html(filename=None, title=None, maximize=True)[source]#
Save the current map as a standalone HTML file.
- Parameters:
filename (Union[str, pathlib.Path, TextIO, IO[str], None]) – where to save the generated HTML file.
title (Optional[str])
maximize (bool)
- Return type:
Union[None, str]
- Other args:
title: A title for the exported map. This will show as the browser tab name.
- Returns:
If filename is not passed, returns the HTML content as a str.
- Parameters:
filename (Union[str, pathlib.Path, TextIO, IO[str], None])
title (Optional[str])
maximize (bool)
- Return type:
Union[None, str]