We have recently been doing a series of posts about Sentinel and Landsat imagery on Amazon Web Services (AWS), including releasing a KML file that automatically retrieves thumbnails of Landsat 8 imagery from AWS and creates animations with them.
We mentioned at the time that the Landsat images are not all perfectly aligned with each other and we had adjusted each image slightly to try and create smoother animations. To do this we used a simplified model that assumed that the imagery squares were all aligned with latitude and longitude, with up being North. It turns out that our assumptions were not valid and there was still significant ‘shake’ visible in ground features in many animations, especially those of Antarctica.
After some investigation we discovered that not only do the Landsat tiles tilt to the right as per the satellite’s orbit, but the images are placed into the thumbnails at an angle, results in further rotations overall.
The imagery on AWS is provided with a file whose name ends with MTL that contains a variety of metadata for the image. This includes the coordinates of the corners of the thumbnails (this is the whole thumbnail including the black areas). If we have two thumbnails offset from each other as shown as the red and green squares in the image below left, then in our animation we need to adjust the top of one of the images by the amount shown as the ‘top offset’. Thinking of it as purely Cartesian coordinates, to work it out in latitude and longitude it involves a series of rotations and translations, which gets rather complicated. However, we realised that instead, we could stick to proper geographic calculations, for which we already have the key routines that we worked out when working on our post on drawing circles in Google Earth. It mostly relies on an open source package called GeographicLib by Charles Karney, with a few additions also by him but not included in the main library.
Above right we see the mid-point (red circle) of the top of the red square, the mid-point (green circle) of the top of the green square, and what is known as the ‘cross track intercept’ for the green point to the thin red line. The cross track intercept is the closest point on a great circle to a location not on the circle. The distance we were looking for is from the red circle to the cross track intercept. Although this all sounds complicated, it is actually only a few lines of code, because all the hard work is done by GeographicLib. We simply repeated this for all for sides and for every frame in the animation and it worked! The animations are now much more stable even over Antarctica.
Our conclusion overall, is that although geographic coordinates can be very complicated, sometimes it is actually easier to work with them than trying to simplify things, as the heavy lifting can be done by ready-made libraries of code.
Because the thumbnails are actually higher resolution than what you can see in the popup, we have also added the ability to zoom and pan the animation. Just use the mouse scroll wheel to zoom in and out and drag the image with the mouse to pan. I am afraid we don’t have a Mac to test on, so we are not sure if this works on Mac. Let us know in the comments if it doesn’t and we will try adding keyboard controls. Remember, these are only thumbnails so don’t expect great resolution when zoomed in.