You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create an animation of a trajectory using Cartopy and FuncAnimation. I have the trajectory stored in a GeoDataFrame with latitude, longitude and date time columns, which I want to visualise.
The trajectory moves across the globe, but I want to zoom in and therefore aim to have the basemap to be updated depending on the extent. I want to use satellite imagery as basemap, and I am using GoogleTiles from cartopy.io.img_tiles.
However, the image seems to only load at the initial extent, and is not updated in the new frames. The same happens when using 'stock_img()'. Interestingly, features such as coastlines and borders do load for the entire globe. To visualise my problem, view the images attached.
Code to reproduce
Function I am using:
# Function to animate with moving basemapsdefplot_animation_moving(gdf, zoom_level=8, extent_margin=4, tail_length=50, frames_between_points=10, interval=100):
tiler=GoogleTiles(style="satellite")
mercator=tiler.crs# Set up the figure and axisfig, ax=plt.subplots(figsize=(12, 12), subplot_kw={'projection': mercator})
# Initial extentinitial_extent= [gdf.iloc[0]['lon']-extent_margin, gdf.iloc[0]['lon']+extent_margin, gdf.iloc[0]['lat']-extent_margin, gdf.iloc[0]['lat']+extent_margin]
ax.set_extent(initial_extent)
# Add background and featuresax.add_image(tiler, zoom_level)
# ax.stock_img()ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.coastlines(resolution='10m')
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.LAKES, alpha=0.5)
ax.add_feature(cfeature.RIVERS)
# Loop through each pair of points and create points in betweenlats_list= []
lons_list= []
dates_list= []
foriinrange(len(gdf)):
# create lat, lon and date sequences
...
lats_list.append(lats)
lons_list.append(lons)
dates_list.append(dates)
# Concatenate pointslats=np.concatenate(lats_list)
lons=np.concatenate(lons_list)
dates=np.concatenate(dates_list)
# Create a point with tail object on the Basemappoint, = ...
tail, = ...
date_text= ...
# Update the point positiondefupdate(frame):
# Update point, tail and datepoint.set_data([lons[frame]], [lats[frame]])
current_date=pd.to_datetime(dates[frame])
date_text.set_text(f'{current_date.strftime("%Y-%m-%d %H:00")}')
# Update the map extent to follow the lineax.set_extent([lons[frame] -extent_margin, lons[frame] +extent_margin, lats[frame] -extent_margin, lats[frame] +extent_margin])
returnpoint, tail, date_text# Create the animationani=FuncAnimation(fig, update, frames=tqdm.tqdm(range(len(lats)), file=sys.stdout), blit=False, interval=interval),
ax.add_image(tiler, zoom_level) # --> doesn't helpani.save("example.mp4")
Without success, I have tried the following:
Starting the first frame(s) with large extent, hoping the imagery loads for the entire globe and then to zoom in again at later frames
Creating a new ax at every update and/or returning the ax at the update function
Creating a list of axes with an ax for every point, and then setting axes visible one by one
My question therefore is: how do I correctly update the basemap image so that it loads when the point is moving across the globe? Is this possible, or am I misunderstanding something?
The text was updated successfully, but these errors were encountered:
Looks like the image is only worked out at the first draw, and there is a comment in the code that suggests there was an intention to change that at some point:
But, it doesn't look like GoogleTiles inherit from the RasterSource to be used with that method.
This would be nice to add some examples explaining how to use these capabilities and it probably needs some updates to the various artist classes to allow for that dynamic image grabbing from more sources.
Description
I want to create an animation of a trajectory using Cartopy and FuncAnimation. I have the trajectory stored in a GeoDataFrame with latitude, longitude and date time columns, which I want to visualise.
The trajectory moves across the globe, but I want to zoom in and therefore aim to have the basemap to be updated depending on the extent. I want to use satellite imagery as basemap, and I am using GoogleTiles from cartopy.io.img_tiles.
However, the image seems to only load at the initial extent, and is not updated in the new frames. The same happens when using 'stock_img()'. Interestingly, features such as coastlines and borders do load for the entire globe. To visualise my problem, view the images attached.
Code to reproduce
Function I am using:
Without success, I have tried the following:
My question therefore is: how do I correctly update the basemap image so that it loads when the point is moving across the globe? Is this possible, or am I misunderstanding something?
The text was updated successfully, but these errors were encountered: