Skip to content

Instantly share code, notes, and snippets.

@darrenwiens
Last active January 29, 2023 11:17
Show Gist options
  • Save darrenwiens/916257bb9bf91287ee1ab53b97102521 to your computer and use it in GitHub Desktop.
Save darrenwiens/916257bb9bf91287ee1ab53b97102521 to your computer and use it in GitHub Desktop.
Make a Leafmap time series animation from STAC query results
import ipyleaflet
import json
import leafmap
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": "2000-10-01T00:00:00Z/2021-11-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=[49.9, -102.5], zoom=10)
m.add_time_slider(layers_dict, time_interval=2)
m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment