Skip to content

22 time slider

image image image

Using time slider for visualizing timeseries images

Uncomment the following line to install leafmap if needed.

1
# !pip install leafmap

This notebook requires the ipyleaflet plotting backend. Folium is not supported.

1
from leafmap import leafmap

First, you need to sign up a Planet account and get an API key. See https://developers.planet.com/quickstart/apis. Uncomment the following line to pass in your API key.

1
# os.environ["PLANET_API_KEY"] = "12345"

Specify the map center and zoom level.

1
2
m = leafmap.Map(center=[38.2659, -103.2447], zoom=13)
m

Use the time slider to visualize Planet quarterly mosaic.

1
2
3
4
m = leafmap.Map()
layers_dict = leafmap.planet_quarterly_tiles()
m.add_time_slider(layers_dict, time_interval=1)
m

Use the time slider to visualize basemaps.

1
2
3
4
5
m = leafmap.Map()
m.clear_layers()
layers_dict = leafmap.basemap_xyz_tiles()
m.add_time_slider(layers_dict, time_interval=1)
m

Use the time slider to visualize COG assets found within STAC items.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ipyleaflet
import json
import requests

stac_api = "https://earth-search.aws.element84.com/v0"
search_endpoint = f"{stac_api}/search"

collection = "sentinel-s2-l2a-cogs"
payload = {
    "bbox": [
        -102.83340454101562,
        49.77860375256143,
        -102.41043090820312,
        50.05273014900257,
    ],
    "datetime": "2021-07-01T00:00:00Z/2021-10-01T12:31:12Z",
    "collections": [collection],
    "limit": 10,
    "query": {"eo:cloud_cover": {"gte": 0, "lte": 10}},
}

headers = {"Content-Type": "application/json"}

response = requests.request(
    "POST", search_endpoint, headers=headers, data=json.dumps(payload)
)

features = response.json()["features"]
features.sort(key=lambda x: x["properties"]["datetime"], reverse=False)

layers_dict = {}
for feature in features:
    feature_id = feature["id"]
    print(feature_id)

    url = leafmap.stac_tile(
        f"{stac_api}/collections/{collection}/items/{feature_id}", bands=["visual"]
    )
    tile_layer = ipyleaflet.TileLayer(
        url=url,
        name=feature_id,
    )
    layers_dict[feature_id] = tile_layer

m = leafmap.Map(center=[50.093079, -103.152825], zoom=11)
m.add_time_slider(layers_dict, time_interval=2)
m