Geo modules

The Geo modules of the vois library contains functions and classes to display geospatial content on an interactive map.

_images/line.png

Map module

Map widget for interactive display of geospatial datasets

class Map.Map(**kwargs: Any)[source]

Map widget for interactive display of geospatial datasets. This class inherits from the ipyleaflet.Map class and adds methods and controls to simplify the Map customisation.

Parameters:
  • width (str, optional) – Width of the Map widget (default is ‘100%’).

  • height (str, optional) – Height of the Map widget (default is ‘600px’).

  • show_fullscreen (bool, optional) – Show or Hide the fullscreen control (default is True).

  • show_search (bool, optional) – Show or Hide the Search control (default is True).

  • show_scale (bool, optional) – Show or Hide the Scale control (default is True).

  • show_coordinates (bool, optional) – Show or hide the Coordinates control (default is True).

  • show_overview (bool, optional) – Show or hide the Overview control (default is False).

  • show_basemaps (bool, optional) – Show or hide the Basemaps toggle control (default is True).

  • color_first (str, optional) – Main color of the overlapped widgets (default is settings.color_first).

  • color_second (str, optional) – Secondary color of the overlapped widgets (default is settings.color_second).

  • dark (bool, optional) – Dark flag (default is settings.dark_mode).

  • basemapindex (int, optional) – Initial basemap index (0=EC, 1=Esri, 2=Google), default is 0.

  • onclick (python function, optional) – Callback function to call on click (receives as parameter: map, lon, lat, zoom), default is None.

Example

Creation of a map instance displaying an overview window:

from IPython.display import display
from vois.geo import Map

m = Map(show_overview=True, center=[52,12], zoom=4, basemapindex=1)
display(m)
Map widget

Fig. 114 Example of a Map with overview

clear()[source]

Remove all the additional layers from the map.

addLayer(tileLayer, name=None, opacity=1.0)[source]

Add a new layer to the map.

Parameters:
  • tileLayer (ipyleaflet.TileLayer or a class that has a tileLayer() callable) – Layer to add to the map

  • name (str, optional) – Name of the layer (default is None)

  • opacity (float, optional) – Opacity of the layer in the range [0.0,1.0] (default is 1.0)

Returns:

layer – The layer added to the map

Return type:

instance of ipyleafler.Layer

property width

Get/Set the width of the Map widget.

property height

Get/Set the height of the Map widget.

property show_fullscreen

Display or hides the Fullscreen control.

property show_coordinates

Display or hides the Coordinates control.

Display or hides the Search control.

property show_scale

Display or hides the Scale control.

property show_basemaps

Display or hides the Basemaps selection control.

property show_overview

Display or hides the Overview control.

property color_first

Get/Set the primary color.

property color_second

Get/Set the secondary color.

property dark

Get/Set the dark mode flag.

property basemapindex

Get/Set the current basemap (index from 0 to 1).

property onclick

Get/Set the python function to call when the user clicks on the map.

property drawctrl

Display or hides the Feature Draw control. The wktstrings member of the Map class contains the list of all the features added in WKT format.

_images/line.png

mapUtils module

Utilities functions for maps

mapUtils.EmptyBasemap()[source]

Returns a fully gray basemap TileLayer instance.

mapUtils.OSM_EC()[source]

Returns a OpenStreetMap European Commission compliant TileLayer instance.

mapUtils.CartoLabels()[source]

Returns a TileLayer instance displaying only EC compliant labels.

mapUtils.EsriWorldImagery()[source]

Returns Esri WorldImagery TileLayer instance.

mapUtils.GoogleRoadmap()[source]

Returns Google Roadmap TileLayer instance.

mapUtils.GoogleSatellite()[source]

Returns Google Satellite TileLayer instance.

mapUtils.GoogleHybrid()[source]

Returns Google Hybrid TileLayer instance.

mapUtils.BDAPLayer(p)[source]

Returns a TileLayer instance from a BDAP ImageProcess or VectorLayer instance passed as input parameter.

mapUtils.addLayer(m, tLayer, name, opacity=1.0)[source]

Add or substitutes a layer given a name.

Parameters:
  • m (ipyleaflet.Map instance) – Map where the layer is to be added.

  • tLayer (ipyleaflet.TileLayer instance) – Layer to add to the map.

  • name (str) – Name of the layer

  • opacity (float, optional) – Opacity of the layer in the [0.0,1.0] range. Default is 1.0.

Returns:

tLayer – The layer added to the map.

Return type:

ipyleaflet.TileLayer instance

mapUtils.getLayer(m, name)[source]

Search for a layer of a map by name.

Parameters:
  • m (ipyleaflet.Map instance) – Map where to search for the layer.

  • name (str) – Name of the layer.

Returns:

tLayer – If a layer with the name exists on the map it is returned, otherwise the function returns None.

Return type:

ipyleaflet.TileLayer instance

mapUtils.removeLayer(m, name)[source]

Remove a layer from a map given its name.

Parameters:
  • m (ipyleaflet.Map instance) – Map where to search for the layer.

  • name (str) – Name of the layer to remove.

mapUtils.removeAllPopups(m)[source]

Remove all instances of ipyleaflet.leaflet.Popup class present in the map.

Parameters:

m (ipyleaflet.Map instance) – Map where the popups must be removed.

mapUtils.clear(m)[source]

Remove all layer except current first layer from a map.

Parameters:

m (ipyleaflet.Map instance) – Map to be cleared.

mapUtils.getCardByName(m, name, position='topright', class_='pa-0 ma-0')[source]

Searches the controls of the Map m to find a control added as a Widget by using its name. If the control is not found, a new control is added to the map.

Parameters:
  • m (ipyleaflet.Map instance) – Map instance.

  • name (str) – Name of the card to search for.

  • position (str, optional) – Position of the card inside the map. Valid positions are ‘bottomleft’, ‘bottomright’, ‘topleft’ and ‘topright’. Default is ‘topright’.

  • class (str, optional) – Margins to set for the adde card (default is ‘pa-0 ma-0’)

Returns:

c – The card added to the map that can be filled with any type of widgets content by setting its children property.

Return type:

v.Card instance

mapUtils.removeCardByName(m, name)[source]

Remove a WidgetControl Card from the map given its name, if present.

Parameters:
  • m (ipyleaflet.Map instance) – Map instance.

  • name (str) – Name of the card to search for.

mapUtils.getCoordinatesCard(m)[source]

Searches the controls of the Map m to find the coordinates control (where the lat/lon coordinates are displayed at mouse move) and returns a v.Card instance.

mapUtils.removeCoordinates(m)[source]

Remove the WidgetControl dedicated to the display of the coordinates at mouse move.

mapUtils.addOverview(m, color='red', position='bottomright', overviewLayer=None)[source]

Add an overview map.

Parameters:
  • m (ipyleaflet.Map instance) – Map instance.

  • color (str, optional) – Color of the rectangle that displays the current zoom of the map inside the overview map.

  • position (str, optional) – Position of the card inside the map. Valid positions are ‘bottomleft’, ‘bottomright’, ‘topleft’ and ‘topright’. Default is ‘bottomright’.

  • overviewLayer (ipyleaflet.TileLayer instance, optional) – Optional layer to be displayed on the overview map (default is None).

mapUtils.removeOverview(m)[source]

Remove the overview map, if present.

mapUtils.toImage(m)[source]

Save the current map content as a PIL image.

Parameters:

m (ipyleaflet.Map instance) – Map instance.

Returns:

img – A raster image displaying the current content of the map.

Return type:

PIL/Pillow image

_images/line.png