Geotagging JPEG files


Most photo mosaic generation software requires that the photos be geotagged as a prerequisite. That is, the GPS latitude/longitude coordinates must be incorporated into the EXIF metadata. Many cameras have a built-in GPS but it is generally accepted that this isn’t adequate because (a) the GPS patch antenna is facing sideways instead of up and (b) the camera is moving at about 10 m/s and the GPS units built into cameras are built for walking-around speeds.

A better option is to use the GPS data from the flight log of the APM flight controller. The idea is to read the time stamp from the EXIF data of the photo and match it to the right time stamp of from the flight log. Then take the GPS lat/lon from that time and insert it into the EXIF metadata.  There may be some interpolation involved, but you get the idea. There is a geo-tagging utility built in to the Mission Planner ground control station software but I found the utility to be pretty buggy.  And since there are no error messages, when it wouldn’t work I was dead in the water without any clue on how to fix it.

Fortunately, I found a reliable alternative.  The exiftool software can do exactly what we need (I reported on exiftool previously as a way to recover the time stamp after the photos went through an NDVI conversion).  All that exiftool needs is a file with time-stamped GPS data.  It supports a bunch of file types, but KML files are the easiest to generate from the flight log. 

One issue is that the flight controller clock and the camera clock are rarely exactly synchronized.  ExifTool has an option called geosync to take care of this (see example below for syntax).  The easiest way to find the offset is to take a photo of the Mission Planner clock with the camera.

Here are the few, simple, steps:

1.  Using the Mission Planner, generate a "KML" file from the flight log (“Telemetry Logs” tab >> Tlog>KML button).  Note that Mission Planner is being almost constantly updated.  This was the sequence in late 2013 but it may shift.

2.  Mission Planner actually generates a KMZ file, which is a zipped KML file.  To make the shift back to KML, change the .kmz extension to .zip.  Unzip it using a regular ZIP utility and the .kml file will come spilling out.

3.  Run exiftool with this syntax (here’s a link to the full description of the geotagging capabilities):
exiftool –geotag flight_log.kml geosync=+5 photo_directory
In this example, the camera clock is 5 seconds behind the flight controller.  Use a negative number if it goes the other way.  Note that this sign convention is the opposite of what is used by the geotagging feature in the Mission Planner.

Once I figured out all the upfront steps, this process worked flawlessly.  Note that if the bugs in the Mission Planner utility are resolved that route would be a simpler.  But for now, exiftool provides a reliable fallback option.