GSKY WMS with ipyleafet and widgets

Please note: If the images/maps below are not shown, please click here to see a completed preview of the interactive features of this notebook.

The following libraries will need to be imported for the below example.

[1]:
from ipyleaflet import WMSLayer, Map, LayersControl
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from IPython.display import display
from owslib.wms import WebMapService
[2]:
gsky_url = 'http://gsky.nci.org.au/ows/dea'
wms = WebMapService(gsky_url, version='1.3.0')
available_layers = list(wms.contents)

Defining widgets

Let’s begin by defining some widgets for GSKY layers, times, latitudes and longitudes:

[3]:
# LS5 NBAR & NBART layers

layer = widgets.Select(
    options = available_layers,
    description='Layer:',
    disabled=False
)


# Latitudes

lat_slider = widgets.IntSlider(
    value=37,
    min=-43,
    max=-10,
    step=1,
    description='Lat:',
    disabled=False,
    continuous_update=False,
    orientation='horizontal',
    readout=True,
    readout_format='d'
)

# Longitude

lon_slider = widgets.IntSlider(
    value=89,
    min=113,
    max=153,
    step=1,
    description='Lon:',
    disabled=False,
    continuous_update=False,
    orientation='horizontal',
    readout=True,
    readout_format='d'
)

Selecting Layers

Now we can start by first selecting the layer and (lat, lon) region we would like to view:

[4]:
display(layer)
display(lat_slider)
display(lon_slider)

Next, we’ll ask GSKY what the available time positions are and select one:

[5]:
date = widgets.Select(
    options=wms[format(layer.value)].timepositions,
    description='Date:',
    disabled=False
)
[6]:
display(date)
[7]:
styles = widgets.Select(
    options=wms[layer.value].styles,
    description='Style:',
    disabled=False
)
[8]:
display(styles)

Let’s confirm the variables we have chosen:

[9]:
print('latitude = {0}'.format(lat_slider.value))
print('longitude = {0}'.format(lon_slider.value))
print('layer = {0}'.format(layer.value))
print('date = {0}'.format(date.value))
print('style = {0}'.format(styles.value))
latitude = -29
longitude = 140
layer = landsat8_nbar_16day
date = 2013-09-27T00:00:00.000Z
style = {'title': 'True colour'}

Adding layers to the ipyleaflet Map

Let’s use the ipyleaflet Map function to plot a map with a center of our lat and lon values.

[10]:
wms = WMSLayer(url='http://gsky.nci.org.au/ows/dea',
                layers=layer.value,
                Styles=styles.value,
                name=layer.value,
                time=date.value,
                tile_size=35,
                transparent=False,
                opacity=1)

m = Map(layers=(wms,), center=(lat_slider.value, lon_slider.value), zoom=8)
m
# Note: we have to zoom in sufficiently so that our gsky wms layer will show. A zoom of 9 should be sufficient for this demonstration.

We can add additional layers from the collection and add them to a layer manager.

[11]:
wms1 = WMSLayer(url='http://gsky.nci.org.au/ows/dea',
                layers='landsat8_geomedian',
                name='landsat8_geomedian',
                Styles='fc',
                time=date.value,
                transparent=False)

wms2 = WMSLayer(
    url="https://demo.boundlessgeo.com/geoserver/ows?",
    layers="nasa:bluemarble",
    name="nasa:bluemarble",
    opacity=1
)

m2 = Map(layers=(wms2, wms, wms1), center=(lat_slider.value, lon_slider.value), zoom=9)
m2.add_control(LayersControl())
m2

The following material uses Geoscience Australia’s Earth Observation Collection. Additional information about this data collection can be found here

For this tutorial we will explore the ipyleaflet Jupyter widgets. For information on ipyleaflet and how to clone and installing, please visit here