Timelapse: 2. Map Production

Thursday, December 24, 2015

This is the second in the series on creating map overlays for timelapse videos from a series of photos. With all the photos now time synced and geotagged, the next step was to produce the actual overlay. And the end result was going to be this:

1. Base Map Preparation

Initial processing and map preparation was undertaken using QGIS. I needed a donor outline of the UK so went for the relatively lightweight worldborders. I then created a new shapefile, digitized around the UK and used this to clip the UK out of the world dataset. This dataset was then projected to British National Grid and finally converted in to a GeoTIFF.

2. Moving marker

Generating the moving marker was the bespoke part and Python the solution! With my Python being a little rusty I asked my colleague Niels Anders if he could rustle up some code to handle this. First things first, what were the Python settings??

Well we used WinPython 2.7.6 (great because it runs as a portable app) with the following libraries: Gpxpy, Pyproj and gdal (which includes ogr). As I noted earlier this month, the latest version of WinPython has Pip integrated which makes installing extra libraries a breeze. Just type “pip install ‘library’”. The only one that didnt work for me was pyproj. In this case you can download the pre-compiled Gohlke binaries. Download the cp27 version (Python 2.7) for either 32 or 64-bit. Then type:

pip install pyproj-1.9.4-cp27-none-win_amd64.whl

You should now be in a position to run the Python script (which we’ve called “timelapse”) which you can download below.

This accepts three inputs: the basemap as a GeoTIFF, a shapefile of the route and a CSV of the image names/coordinates (as exported from ExifTool). So it would look like:

python timelapse.py ‘tif’ ’shp’ ‘csv’

Such as

python timelapse.py uk.tif route_new.shp coords_master.csv

This outputs as directory of images with the same name as the photos to a “png” subdirectory. The basic workflow is as follows:

1. Check if png folder exists and if not, create it.

2. Load basemap geotiff (assumed to be in BNG)

3.Read SHP route tracklog (as WGS84) and convert to BNG

4.Read CSV that contains WGS84 coordinates for the photos

5.Iterate over each photo coordinate:
a. Project lon/lat to BNG and add to route arrays (x, y)
b. Extract of GOPRO image
c. Create axes and plot:
- basemap (masking out UK to create a transparent backgroun) - entire route (in gray)
- route finished so far (in red)
- current location with a marker
- optimze axes (force equal scale of x,y axes, remove outer box, set extent to min/max x,y)
d. Save as ‘filename’.PNG in the png folder
e. Clear axes for next iteration

This gives us a black map with transparent background, a grey route, a red dot for the current location and then a red route for amount completed so far.

The final installment will taken all these elements to produce the final timelapse.

Add comment

Fill out the form below to add your own comments