I created the following video in R from ground up:
This article will give you a general understanding of the process creating the visualization above. To replicate my results please follow the steps outlined in this REPO.
But first, what is this video about?
Aerothlon is an alpine triathlon race of mountain running, mountain biking and paragliding. I had the pleasure to take part in the 2021 edition in Kleinarl (AT). The video visualizes the efforts of all athletes at 350x speed.
Ok, how to make it?
1. Getting the data
You need the following data for the surrounding area of the tracklogs:
- Digital elevation data
- Overlay satellite image
Although there are many free sources available out there within R, the geoviz package provides great one-liners for this purpose, e.g.:
digital_elev_data <- geoviz::mapzen_dem(center_of_location_lat, center_of_location_long, area_side_in_km)
2. Prepare the 3D scene
The heart of this visualization is the awesome R package rayshader which renders the 3D scene of the elevation data, projects the overlay image onto the surface and takes care of shading as well.
The package is fully automated, supports piping and so very intuitive. After converting the elevation data into a matrix (named elmat below) you just basically need to play with the sun altitude and direction:
scene <- elmat %>% rayshader::sphere_shade(sunangle = sunangle, sunaltitude = sunaltitude) %>% rayshader::add_shadow(rayshader::ray_shade(elmat) %>% rayshader::add_shadow(rayshader::lamb_shade(elmat) %>% rayshader::dd_overlay(overlay_image) %>% rayshader::plot_3d(elmat)
This will pop up an rgl window showing your scene rendered in 3D.
3. Create animation frames
The concept is to sequentially add a fraction of the tracklogs to the scene (utilizing the geoviz::add_gps_to_rayshader() function), adjust camera view and save each step as a standalone image.
To large extend this visualization and the corresponding technology was inspired by the package rayshaderanimate, however I decided to write my own animation function due to the massive changes needed to fit my needs:
create_rayshader_animantion_frames() wraps the snippets above inside a loop and has an extended argument list to adjust e.g. camera movements, video resolution, video length.
Once the frames were generated I retouched each using a tailor made Photoshop batch process. (This is not documented, but not essential either.)
4. Render video
For this you need to have ffmpeg installed on your computer. This little application will render an mp4 video from the images generated before. With the function render_rayshader_animantion() under my repo you can invoke ffmpeg from R (concept again taken from the package rayshaderanimate).
And that’s it!
I am proudly contributing to www.r-bloggers.com as well with this post .