ecoscope.mapping.map
#
Module Contents#
- class ecoscope.mapping.map.EcoMapMixin#
- add_speedmap(trajectory, classification_method='equal_interval', num_classes=6, speed_colors=None, bins=None, legend=True)#
- Parameters:
trajectory (geopandas.GeoDataFrame) –
classification_method (str) –
num_classes (int) –
speed_colors (List) –
bins (List) –
legend (bool) –
- class ecoscope.mapping.map.EcoMap(*args, static=False, print_control=True, **kwargs)#
Bases:
EcoMapMixin
,ecoscope.contrib.foliumap.Map
The Map class inherits folium.Map. By default, the Map will add OpenStreetMap as the basemap.
- Returns:
folium map object.
- Return type:
object
- add_gdf(data, *args, simplify_tolerance=None, **kwargs)#
Wrapper for geopandas.explore._explore.
- add_legend(*args, **kwargs)#
Patched method for allowing legend hex colors to start with a “#”.
- add_north_arrow(position='topright', scale=1.0)#
- Parameters:
position (str) – Possible values are ‘topleft’, ‘topright’, ‘bottomleft’ or ‘bottomright’.
scale (float) – Scale dimensions of north arrow.
- add_title(title, font_size='32px', font_style='normal', font_family='Helvetica', font_color='rgba(0,0,0,1)', position=None, background_color='#FFFFFF99', outline='0px solid rgba(0, 0, 0, 0)', **kwargs)#
- Parameters:
title (str) – Text of title.
font_size (str) – CSS font size that includes units. font_style : str
font_family (str"Helvetica",) – Font family selection; Could be one or more separated by spaces.
font_color (str) – Text color (css color property); supports rgb, rgba and hex string formats.
position (dict|None) –
Dict object with top, left and bottom margin values for the title container position. ex. {
”top”: “10px”, “left”: “25px”, “right”: “0px”, “bottom”: “0px”
}
All keys are optional in the dictionary (could be passed some of them as necessary). Values could be passed as px or accepted css metric. Default None.
background_color (str) – Box background color; supports rgb, rgba and hex string formats. Default ‘#FFFFFF99’.
outline (str) –
Element outline values (width style color_with_transparency). Could be passed as a string with spaced separated values or a dict structure: ex. {
”width”: “1px”, “style”: “solid”, “color”: “#FFFFFF99” # or rgb/rgba tuple (0, 0, 0, 0)
}
kwargs – Additional style kwargs. Underscores in keys will be replaced with dashes
font_style (str) –
- _repr_html_(**kwargs)#
Displays the HTML Map in a Jupyter notebook.
- to_html(outfile, **kwargs)#
- Parameters:
outfile (str, Pathlike) – Output destination
- to_png(outfile, sleep_time=10, **kwargs)#
- Parameters:
outfile (str, Pathlike) – Output destination
sleep_time (int, optional) – Additional seconds to wait before taking screenshot. Should be increased if map tiles in the output haven’t fully loaded but can also be decreased in most cases.
- add_ee_layer(ee_object, visualization_params, name)#
Method for displaying Earth Engine image tiles.
- Parameters:
ee_object –
visualization_params –
name –
- Return type:
None
- zoom_to_bounds(bounds)#
Zooms to a bounding box in the form of [minx, miny, maxx, maxy].
- Parameters:
bounds ([x1, y1, x2, y2]) – Map extent in WGS 84
- zoom_to_gdf(gs)#
- Parameters:
gs (gpd.GeoSeries or gpd.GeoDataFrame) – Geometry to adjust map bounds to. CRS will be converted to WGS 84.
- add_local_geotiff(path, zoom=False, cmap=None, colorbar=True)#
Displays a local GeoTIFF.
- Parameters:
path (str, Pathlike) – Path to local GeoTIFF
zoom (bool) – Zoom to displayed GeoTIFF
cmap (matplotlib.colors.Colormap or str or None) – Matplotlib colormap to apply to raster
colorbar (bool) – Whether to add colorbar for provided cmap. Does nothing if cmap is not provided.
- add_print_control()#
- add_datashader_gdf(gdf, geom_type, name=None, width=600, height=600, cmap=['lightblue', 'darkblue'], ds_agg=None, zoom=True, opacity=1, **kwargs)#
Overlays a static visualization of the given gdf generated using Datashader
- Parameters:
gdf (geopandas.GeoDataFrame) – GeoDataFrame used to create visualization (geometry must be projected to a CRS)
geom_type (str) – The Datashader canvas() function to use valid values are ‘polygon’, ‘line’, ‘point’
name (string) – The name of the image layer to be displayed in Folium layer control
width (int) – The canvas width in pixels, determines the resolution of the generated image
height (int) – The canvas height in pixels, determines the resolution of the generated image
cmap (list of colors or matplotlib.colors.Colormap) – The colormap to use for the generated image
ds_agg (datashader.reductions function) – The Datashader reduction to use
zoom (bool) – Zoom to the generated image
opacity (float) – Sets opacity of overlaid image
kwargs – Additional kwargs passed to datashader.transfer_functions.shade
- class ecoscope.mapping.map.ControlElement(html, position='bottomright')#
Bases:
branca.element.MacroElement
Class to wrap arbitrary HTML as Leaflet Control.
- Parameters:
html (str) – HTML to render an element from.
position (str) – Possible values are ‘topleft’, ‘topright’, ‘bottomleft’ or ‘bottomright’.
- _template#
- class ecoscope.mapping.map.FloatElement(html, left='', right='', top='', bottom='')#
Bases:
branca.element.MacroElement
Class to wrap arbitrary HTML as a floating Element.
- Parameters:
html (str) – HTML to render an element from.
left (str) – Distance between edge of map and nearest edge of element. Two should be provided. Style can also be specified in html.
right (str) – Distance between edge of map and nearest edge of element. Two should be provided. Style can also be specified in html.
top (str) – Distance between edge of map and nearest edge of element. Two should be provided. Style can also be specified in html.
bottom (str) – Distance between edge of map and nearest edge of element. Two should be provided. Style can also be specified in html.
- _template#
- class ecoscope.mapping.map.GeoTIFFElement(url, zoom=False)#
Bases:
branca.element.MacroElement
Class to display a GeoTIFF.
- Parameters:
url (str) – URL of GeoTIFF
zoom (bool) – Zoom to displayed GeoTIFF
- _template#
- class ecoscope.mapping.map.PrintControl#
Bases:
branca.element.MacroElement
This is a parent class for Elements defined by a macro template. To compute your own element, all you have to do is:
To inherit from this class
Overwrite the ‘_name’ attribute
Overwrite the ‘_template’ attribute with something of the form:
{% macro header(this, kwargs) %} ... {% endmacro %} {% macro html(this, kwargs) %} ... {% endmacro %} {% macro script(this, kwargs) %} ... {% endmacro %}
- _template#