# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Data Cube OWS Services
#
# This document presents an example of consumption of the OWS services provided with the integration between BDC-ODC.
#

# +
from traitlets import Unicode
from ipyleaflet import Map, WMSLayer, basemaps

from ipyleaflet import Map, FullScreenControl
# -

# Below are the definitions of utilities used in the rest of this example

# +
BDC_MAP_CENTER = (-11.436955216143177, -52.16308593749999)
BDC_SERVICE_URL = "https://brazildatacube.dpi.inpe.br/opendatacube/ows/wms"


def bdc_odc_twms(collection_name: str, time_dimension: str, center = BDC_MAP_CENTER, zoom = 4):
    """Show a BDC data collection indexed on ODC instance via OWS service
    
    Args:
        collection_name (str): Name of collection that will be visualized
        
        time_dimension (str): Time of presented layer (Check WMS get capabilities)
    
        center (tuple): location of map center
        
        zoom (int): map zoom level
    
    Returns:
        TimeWMSLayer: Instance of TimeWMSLayer configured with layer from BDC-ODC OWS Service
    """
    
    class TimeWMSLayer(WMSLayer):
        time = Unicode('').tag(sync=True, o=True)
    
    time_wms = TimeWMSLayer(
        url         = BDC_SERVICE_URL,
        layers      = collection_name,
        time        = time_dimension,
        format      = 'image/png',
        transparent = True,
        attribution = 'BDC-ODC OWS Service'
    )
    
    bdcodc_map = Map(basemap=basemaps.CartoDB.Positron, zoom = zoom, center = center)
    bdcodc_map.add_control(FullScreenControl())
    bdcodc_map.add_layer(time_wms)
    
    return bdcodc_map
    


# -

# **Viewing WMS with time layers**
#
# > The dates used in the views can be retrieved through the [WMS GetCapabilities](https://brazildatacube.dpi.inpe.br/opendatacube/ows/wms?request=GetCapabilities&service=WMS&version=1.3.0).
#

# **LC8_30_16D_STK-1 Collection**

bdc_odc_twms("LC8_30_16D_STK_1", "2019-08-28")

# **S2_10_16D_STK-1 Collection**

bdc_odc_twms("S2_10_16D_STK_1", "2019-08-28")

# **CB4_64_16D_STK-1 Collection**

bdc_odc_twms("CB4_64_16D_STK_1", "2019-08-28")

StarcoderdataJupyterScriptsDedupFiltered