ecoscope.mapping.map#

Module Contents#

ecoscope.mapping.map.TILE_LAYERS#
ecoscope.mapping.map._keep_columns(gdf, keep_columns)#
Parameters:
  • gdf (geopandas.GeoDataFrame)

  • keep_columns (list[str] | None)

Return type:

geopandas.GeoDataFrame

ecoscope.mapping.map._clean_gdf(gdf)#

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 :param keep_columns: A list of dataframe columns to keep (geometry column will always be kept)

Parameters:

gdf (geopandas.GeoDataFrame)

Return type:

geopandas.geodataframe

class ecoscope.mapping.map.EcoMap(static=False, default_widgets=True, *args, **kwargs)#

Bases: 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_widget(widget)#

Adds a deck widget to the map :param widget: :type widget: lonboard.BaseDeckWidget or list[lonboard.BaseDeckWidget]

Parameters:

widget (lonboard._deck_widget.BaseDeckWidget)

static polyline_layer(gdf, color_column=None, tooltip_columns=None, **kwargs)#

Creates a polyline layer to add to a map :param gdf: The data used to create the polyline layer :type gdf: gpd.GeoDataFrame :param tooltip_columns: A list of dataframe columns to be included in the map picking tooltip

Will default to all columns if no list is provided

Parameters:
Return type:

lonboard._layer.PathLayer

static polygon_layer(gdf, fill_color_column=None, line_color_column=None, tooltip_columns=None, **kwargs)#

Creates a polygon layer to add to a map :param gdf: The data used to create the polygon layer :type gdf: gpd.GeoDataFrame :param tooltip_columns: A list of dataframe columns to be included in the map picking tooltip

Will default to all columns if no list is provided

Parameters:
Return type:

lonboard._layer.PolygonLayer

static point_layer(gdf, fill_color_column=None, line_color_column=None, tooltip_columns=None, **kwargs)#

Creates a polygon layer to add to a map :param gdf: The data used to create the point layer :type gdf: gpd.GeoDataFrame :param tooltip_columns: A list of dataframe columns to be included in the map picking tooltip

Will default to all columns if no list is provided

Parameters:
Return type:

lonboard._layer.ScatterplotLayer

add_legend(labels, colors, **kwargs)#

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)#

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)#

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)#

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)#

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)#

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)#

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)#

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)#

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)#
Parameters:
  • layer (str)

  • opacity (float)

Return type:

lonboard._layer.BitmapTileLayer

to_html(filename: None = None, title: str | None = None, maximize: bool = True) str#
to_html(filename: str | pathlib.Path | TextIO | IO[str], title: str | None = None, maximize: bool = True) None

Save the current map as a standalone HTML file.

Parameters:

filename – where to save the generated HTML file.

Keyword Arguments:

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.