birdy.ipyleafletwfs.base module

Ipyleaflet 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

urlstr

The url of the WFS service.

wfs_versionstr

The version of the WFS service to use. Defaults to 2.0.0.

Returns

IpyleafletWFS

Instance from which the WFS layers can be created.

build_layer(layer_typename: str, 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_typenamestr

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

source_mapMap instance

The map instance on which the layer is to be added.

layer_styledict

A layer style dictionary in ipyleaflet GeoJSON style format, for example: { ‘color’: ‘white’, ‘opacity’: 1, ‘dashArray’: ‘9’, ‘fillOpacity’: 0.1, ‘weight’: 1 }. See ipyleaflet documentation for more information.

feature_propertystr

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.

create_feature_property_widget(widget_name: str, feature_property: str | None = None, widget_position: str = '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_namestr

Name of the widget. Must be unique or will overwrite existing widget.

feature_propertystr, optional

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{‘bottomleft’, ‘bottomright’, ‘topleft’, ‘topright’}

Position on the map for the widget.

Notes

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

create_wfsgeojson_layer(layer_typename: str, source_map, layer_style: dict | None = None)[source]

Create a static ipyleaflet 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_typenamestr

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

source_mapMap instance

The map instance from which the extent will be used to filter the request.

layer_styledict, optional

A layer style dictionary in ipyleaflet GeoJSON style format, for example: { ‘color’: ‘white’, ‘opacity’: 1, ‘dashArray’: ‘9’, ‘fillOpacity’: 0.1, ‘weight’: 1 }. See ipyleaflet documentation for more information.

Returns

ipyleaflet.GeoJSON

An instance of an ipyleaflet GeoJSON layer.

feature_properties_by_id(feature_id: int) Any | None[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_idint

The feature id.

Returns

dict

A dictionary of the layer’s properties.

property geojson

Return the imported geojson data in a python object format.

property layer
property layer_list: list

Return a simple layer list available to the WFS service.

Returns

list

A list of the WFS layers available.

property property_list: dict

Return a list containing the properties of the first feature.

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

Returns

dict

A dictionary of the layer properties.

remove_layer()[source]

Remove layer instance and it’s widgets from map.