Hi StackOverflow Community,
I have year-over-year images that I have pulled from Google Earth Image, and I want to animate them so that it's easier to analyze.
I tried to use Folium, which has a plugin that enables the animation with a slider. (i.e. TimestampedGeo). This is the code:
import ee
import folium
import folium.plugins as fplugins
"""
Sources:
- .ipynb#scrollTo=3qB3W9rDfoma
- .html
"""
ee.Authenticate()
ee.Initialize()
dem = ee.Image('USGS/SRTMGL1_003')
m = folium.Map(
location=(chosen_lat, chosen_lon),
zoom_start=9,
height=300
)
features = [
{
"type": "Feature",
"geometry": dem.updateMask(dem.gt(0)).getMapId({}),
"properties": {"times": ["2017-06-02T00:30:00", "2017-06-02T00:40:00"]}
}
]
fplugins.TimestampedGeoJson(
data={
"type": "FeatureCollection",
"features": features,
},
period="PT1M",
add_last_point=True,
).add_to(m)
m
The above code keeps giving this error message:
TypeError Traceback (most recent call last)
hex_cell_0195d7ee-7e8b-7aa1-b548-572c1c39aad2.py in <module>
32 }
33 ]
---> 34
35 fplugins.TimestampedGeoJson(
36 data={
~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/folium/plugins/timestamped_geo_json.py in __init__(self, data, transition_time, loop, auto_play, add_last_point, period, min_speed, max_speed, loop_button, date_options, time_slider_drag_update, duration, speed_slider)
203 elif type(data) is dict:
204 self.embed = True
--> 205 self.data = json.dumps(data)
206 else:
207 self.embed = False
/usr/local/lib/python3.9/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
/usr/local/lib/python3.9/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
/usr/local/lib/python3.9/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
/usr/local/lib/python3.9/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
TypeError: Object of type TileFetcher is not JSON serializable
Does anyone know how to fix this, or whether it's possible for Folium to animate images? I'm also open to trying any Python libraries that can achieve the same.