birdy.ipyleafletwfs.base module

class birdy.ipyleafletwfs.base.IpyleafletWFS(url, wfs_version='2.0.0')[source]

Bases: object

Create a connection to a WFS service capable of geojson output.

This class is a small wrapper for ipylealet to facilitate the use of a WFS service, as well as provide some automation.

Request to the WFS service is done through the owslib module and requires a geojson output capable WFS. The geojson data is filtered for the map extent and loaded as an ipyleaflet GeoJSON layer.

The automation done through build_layer() supports only a single layer per instance is supported.

For multiple layers, used different instances of IpylealetWFS and Ipyleaflet.Map() or use the create_wfsgeojson_layer() function to build your own custom map and widgets with ipyleaflet.

Parameters:
  • url (str) – The url of the WFS service

  • wfs_version (str) – The version of the WFS service to use. Defaults to 2.0.0.

Returns:

Instance from which the WFS layers can be created.

Return type:

IpyleafletWFS

_create_refresh_widget()[source]
_refresh_layer(placeholder=None)[source]

Refresh the wfs layer for the current map extent.

Also updates the existing widgets.

Parameters:

placeholder (string) – Parameter is only there so that button.on_click() will work properly.

_set_widget(widget_name, feature_property, src_map, textbox, widget_position)[source]
build_layer(layer_typename, source_map, layer_style=None, feature_property=None)[source]

Return an ipyleaflet GeoJSON layer from a geojson wfs request.

Requires the WFS service to be capable of geojson output.

Running this function multiple times will overwrite the previous layer and widgets.

Parameters:
  • layer_typename (string) –

    Typename of the layer to display. Listed as Layer_ID by get_layer_list(). Must include namespace and layer name, separated by a colon.

    ex: public:canada_forest_layer

  • source_map (Map instance) – The map instance on which the layer is to be added.

  • layer_style (dictionnary) – ipyleaflet GeoJSON style format, for example { ‘color’: ‘white’, ‘opacity’: 1, ‘dashArray’: ‘9’, ‘fillOpacity’: 0.1, ‘weight’: 1 }. See ipyleaflet documentation for more information.

  • feature_property (string) – The property key to be used by the widget. Use the property_list() function to get a list of the available properties.

clear_property_widgets()[source]

Remove all property widgets from a map.

This function will remove the property widgets from a given map, without affecting other widgets.

Parameters:

src_map (Map instance) – The map instance from which the widgets are to be removed.

create_feature_property_widget(widget_name, feature_property=None, widget_position='bottomright')[source]

Create a visualization widget for a specific feature property.

Will create a widget for the layer and source map. Once the widget is created, click on a map feature to have the information appear in the corresponding box. To replace the default widget that get created by the build_layer() function, set the widget_name parameter to ‘main_widget’.

Parameters:
  • widget_name (string) – Name of the widget. Must be unique or will overwrite existing widget.

  • feature_property (string) – The property key to be used by the widget. Use the property_list() function to get a list of the available properties. If left empty, it will default to the first property attribute in the list.

  • widget_position (string) – Position on the map for the widget. Choose between ‘bottomleft’, ‘bottomright’, ‘topleft’, or ‘topright’.

Notes

Widgets created by this function are unique by their widget_name variable.

create_wfsgeojson_layer(layer_typename, source_map, layer_style=None)[source]

Create a static ipyleaflett GeoJSON layer from a WFS service.

Simple wrapper for a WFS => GeoJSON layer, using owslib.

Will create a GeoJSON layer, filtered by the extent of the source_map parameter. If no source map is given, it will not filter by extent, which can cause problems with large layers.

WFS service need to have geojson output.

Parameters:
  • layer_typename (string) –

    Typename of the layer to display. Listed as Layer_ID by get_layer_list(). Must include namespace and layer name, separated by a colon.

    ex: public:canada_forest_layer

  • source_map (Map instance) – The map instance from which the extent will be used to filter the request.

  • layer_style (dictionnary) – ipyleaflet GeoJSON style format, for example { ‘color’: ‘white’, ‘opacity’: 1, ‘dashArray’: ‘9’, ‘fillOpacity’: 0.1, ‘weight’: 1 }. See ipyleaflet documentation for more information.

Returns:

GeoJSON layer

Return type:

an instance of an ipyleaflet GeoJSON layer.

feature_properties_by_id(feature_id)[source]

Return the properties of a feature.

The id field is usually the first field. Since the name is always different, this is the only assumption that can be made to automate this process. Hence, this will not work if the layer in question does not follow this formatting.

Parameters:

feature_id (int) – The feature id.

Returns:

A dictionary of the layer’s properties

Return type:

Dict

property geojson

Return the imported geojson data in a python object format.

property layer
property layer_list

Return a simple layer list available to the WFS service.

Returns:

A List of the WFS layers available

Return type:

List

property property_list

Return a list containing the properties of the first feature.

Retrieves the available properties for use subsequent use by the feature property widget.

Returns:

A dictionary of the layer properties.

Return type:

Dict

remove_layer()[source]

Remove layer instance and it’s widgets from map.

birdy.ipyleafletwfs.base._map_extent_to_bbox_filter(source_map)[source]

Return formatted coordinates, from ipylealet format to owslib.wfs format.

This function takes the result of ipyleaflet’s Map.bounds() function and formats it so it can be used as a bbox filter in an owslib WFS request.

Parameters:

source_map (Map instance) – The map instance from which the extent will calculated

Returns:

Coordinates formatted to WebFeatureService bounding box filter.

Return type:

Tuple