Saudia XYZ logo Code: create landsat timelapse
Main Source: geemap
Edited by: Saudia.xyz

Uncomment the following line to install geemap if needed.

In [1]:
# !pip install geemap
In [2]:
import geemap

Create Landsat timeseries

In [113]:
import os
import ee
import geemap
In [114]:
Map = geemap.Map(center=(24.7169, 46.6755), zoom=10)
Map

Define an roi or draw a rectangle on the map

In [116]:
roi = ee.Geometry.Polygon(
    [[[46.4502, 24.4809],
      [46.9680, 24.4734],
        [46.9584, 25.0221],
        [46.4694, 24.9873]]], None, False)
In [117]:
#roi = Map.draw_last_feature
In [118]:
collection = geemap.landsat_timeseries(roi=roi, start_year=1985, end_year=2021, start_date='06-10', end_date='09-20')
In [119]:
print(collection.size().getInfo())
37
In [120]:
first_image = collection.first()

vis = {
    'bands': ['NIR', 'Red', 'Green'],
    'min': 0,
    'max': 4000,
    'gamma': [1, 1, 1]
}

Map.addLayer(first_image, vis, 'First image')

Download ImageCollection as a GIF

In [121]:
# Define arguments for animation function parameters.
video_args = {
  'dimensions': 768,
  'region': roi,
  'framesPerSecond': 10,
  'bands': ['NIR', 'Red', 'Green'],
  'min': 0,
  'max': 4000,
  'gamma': [1, 1, 1]
}
In [122]:
work_dir = os.path.join(os.path.expanduser("~"), 'Downloads')
if not os.path.exists(work_dir):
    os.makedirs(work_dir)
out_gif = os.path.join(work_dir, "landsat_ts.gif")
In [123]:
geemap.download_ee_video(collection, video_args, out_gif)
Generating URL...
Downloading GIF image from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/videoThumbnails/dd60057a4dd5cdbb72959825183e603f-e7de6052cd68016428d5b9bbd439d5ea:getPixels
Please wait ...
The GIF image has been saved to: C:\Users\alasm\Downloads\landsat_ts.gif

Add animated text to GIF

In [124]:
geemap.show_image(out_gif)
In [128]:
texted_gif = os.path.join(work_dir, "landsat_ts_text.gif")
geemap.add_text_to_gif(out_gif, texted_gif, xy=('3%', '5%'), text_sequence=1985, font_size=30, font_color='#000000', add_progress_bar=False)
In [129]:
label = 'Urban Growth in Riyadh'
geemap.add_text_to_gif(texted_gif, texted_gif, xy=('2%', '88%'), text_sequence=label, font_size=30, font_color='#000000', progress_bar_color='cyan')
In [130]:
geemap.show_image(texted_gif)