Skip to content

Commit b494aca

Browse files
iamteksonpre-commit-ci[bot]
authored andcommitted
Overlay another layer in get_image_collection_gif function (#1994)
* overlay another layer in gif * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b2de3ce commit b494aca

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

geemap/cartoee.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,10 @@ def get_image_collection_gif(
11591159
file_format="png",
11601160
north_arrow_dict={},
11611161
scale_bar_dict={},
1162+
overlay_layers=[],
1163+
overlay_styles=[],
11621164
verbose=True,
1165+
**kwargs,
11631166
):
11641167
"""Download all the images in an image collection and use them to generate a gif/video.
11651168
Args:
@@ -1175,10 +1178,13 @@ def get_image_collection_gif(
11751178
date_format (str, optional): A pattern, as described at http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html. Defaults to "YYYY-MM-dd".
11761179
fig_size (tuple, optional): Size of the figure.
11771180
dpi_plot (int, optional): The resolution in dots per inch of the plot.
1178-
file_format (str, optional): Either 'png' or 'jpg'.
1181+
file_format (str, optional): Either 'png' or 'jpg'. Defaults to 'png'.
11791182
north_arrow_dict (dict, optional): Parameters for the north arrow. See https://geemap.org/cartoee/#geemap.cartoee.add_north_arrow. Defaults to {}.
11801183
scale_bar_dict (dict, optional): Parameters for the scale bar. See https://geemap.org/cartoee/#geemap.cartoee.add_scale_bar. Defaults. to {}.
1184+
overlay_layers (list, optional): A list of Earth Engine objects to overlay on the map. Defaults to [].
1185+
overlay_styles (list, optional): A list of dictionaries of visualization parameters for overlay layers. Defaults to [].
11811186
verbose (bool, optional): Whether or not to print text when the program is running. Defaults to True.
1187+
**kwargs: Additional keyword arguments are passed to the add_layer() function.
11821188
"""
11831189

11841190
from .geemap import png_to_gif, jpg_to_gif
@@ -1219,6 +1225,43 @@ def get_image_collection_gif(
12191225
# Plot image
12201226
ax = get_map(image, region=region, vis_params=vis_params, cmap=cmap, proj=proj)
12211227

1228+
# check length of overlay layers and styles
1229+
if len(overlay_layers) != len(overlay_styles):
1230+
raise ValueError(
1231+
"The length of overlay_layers and overlay_styles must be the same."
1232+
)
1233+
1234+
for ee_object, style in zip(overlay_layers, overlay_styles):
1235+
if (
1236+
isinstance(ee_object, ee.geometry.Geometry)
1237+
or isinstance(ee_object, ee.feature.Feature)
1238+
or isinstance(ee_object, ee.featurecollection.FeatureCollection)
1239+
):
1240+
overlay_vis_params = (
1241+
None # for vector data, we can pass style parameters directly
1242+
)
1243+
elif (
1244+
isinstance(ee_object, ee.image.Image)
1245+
or isinstance(ee_object, ee.imagecollection.ImageCollection)
1246+
or isinstance(ee_object, ee.imagecollection.ImageCollection)
1247+
):
1248+
overlay_vis_params = style # for raster, we need to pass vis_params
1249+
style = None
1250+
else:
1251+
raise ValueError(
1252+
"The overlay object must be an ee.Geometry, ee.Feature, ee.FeatureCollection, ee.Image, or ee.ImageCollection."
1253+
)
1254+
1255+
add_layer(
1256+
ax,
1257+
ee_object,
1258+
region=region,
1259+
cmap=cmap,
1260+
vis_params=overlay_vis_params,
1261+
style=style,
1262+
**kwargs,
1263+
)
1264+
12221265
# Add grid
12231266
if grid_interval is not None:
12241267
add_gridlines(ax, interval=grid_interval, linestyle=":")

0 commit comments

Comments
 (0)