How to use the WFSGeojsonLayer class

This class provides WFS layers for ipyleaflet from services than avec geojson output capabilities We first have to create the WFS connection and instantiate the map:

[ ]:
from ipyleaflet import Map

from birdy import IpyleafletWFS


url = "http://boreas.ouranos.ca/geoserver/wfs"
version = "2.0.0"

wfs_connection = IpyleafletWFS(url, version)

demo_map = Map(center=(46.42, -64.14), zoom=8)
demo_map

We can then retrieve the available layers. We will use these to create our WFS layer:

Next we create our WFS layer from one of the layers listed above. It is filtered by the extent of the map, seen above.

This next function is a builder and will create, add and configure the map with its two default widgets:

[ ]:
wfs_connection.build_layer(layer_typename="public:HydroLAKES_poly", source_map=demo_map)

The layer created above will have a refresh button, which can be pressed to refresh the WFS layer.

It will also have a property widget in the lower right corner of the map, and will show the feature ID of a feature after you click on it.

It’s also possible to add a new property widget. We first need to retrieve the properties of a feature. The following code returns the properties of the first feature, which should be shared by all features.

We can create a new widget from any of the above properties

The widget_name parameter needs to be unique, else it will overwrite the existing one.

[ ]:
wfs_connection.create_feature_property_widget(widget_name="Wshd_area", feature_property="Wshd_area", widget_position="bottomleft")
demo_map

To replace the default property widget, the same function can be used with the ‘main_widget’ name.

This can be useful when there is no need for the feature ID, or on the off chance that the first property attribute does not contain the feature ID.

[ ]:
wfs_connection.create_feature_property_widget(widget_name="main_widget", feature_property="Lake_area")

The geojson data is available. The results are also filtered by what is visible on the map:

[ ]:
gjson = wfs_connection.geojson
gjson["features"][0].keys()
[ ]:
gjson["totalFeatures"]

A search by ID for features is also available. Let’s set back the main widget to default so we can have access to feature IDs again:

[ ]:
wfs_connection.create_feature_property_widget(widget_name="main_widget")
demo_map

Now click on a feature and replace ‘748’ in the cell below with a new ID number to get the full properties of that feature:

To get rid of all the property widgets:

And finally, to remove the layer from the map: