Skip to content

61 vector to gif

image image image

Creating animated GIF from vector data

Inspired by Johannes Uhl's shapefile2gif, I created a vector_to_gif() function in leafmap that makes it much easier to create animated GIF from vector data with only one line of code. The sample dataset used in this notebook is a subset of the dataset retrieved from the shapefile2gif repo. Credits to Johannes Uhl. For more information about the datasets, check out the references below:

  • Uhl, Johannes H; Leyk, Stefan (2022), "MTBF-33: A multi-temporal building footprint dataset for 33 counties in the United States (1900–2015)", Data in Brief, 43, 108369. DOI: 10.1016/j.dib.2022.108369
  • Uhl, Johannes H; Leyk, Stefan (2022), “MTBF-33: A multi-temporal building footprint dataset for 33 U.S. counties at annual resolution (1900-2015)”, Mendeley Data, V2. DOI: 10.17632/w33vbvjtdy.2

Uncomment the following line to install leafmap if needed.

1
# !pip install -U leafmap
1
import leafmap
1
2
3
# A subset of the dataset retrieved from https://github.com/johannesuhl/shapefile2gif
url = "https://opengeos.org/data/us/boulder_buildings.zip"
data = leafmap.download_file(url, unzip=False)
1
2
3
m = leafmap.Map(center=[39.9898, -105.2532], zoom=14)
m.add_vector(data, layer_name="Buildings")
m
1
2
3
out_gif = "buildings.gif"
colname = "year_built"
title = "Building Evolution in Boulder, Colorado, USA (1950-2015)"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
leafmap.vector_to_gif(
    data,
    out_gif,
    colname,
    vmin=1950,
    vmax=2015,
    step=10,
    facecolor="black",
    figsize=(10, 8),
    title=title,
    xy=("1%", "1%"),
    fontsize=20,
    progress_bar_color="blue",
    progress_bar_height=10,
    dpi=300,
    fps=10,
    mp4=False,
    verbose=True,
)