5. January 2015
In a recent post, I discussed the new drone that I got for the holidays and a bit about how I was using it for developing map products. I do this using structure from motion algorithms and when working with a lot of images it is a great help if there is a good initial estimate of the image location. This is where geotagging comes in.
If you have a smartphone, then you are familiar with geotagging. Most iPhone and Android devices tag their images when they are collected. That is great if you are uploading to Facebook or Pinterest, but may not be the best for mapping applications. I need images that have an accurate time stamp and complete position information, including latitude, longitude, and altitude. Many smartphones include the first two, but often altitude is ignored. In my case one of the cameras I use is a GoPro Hero3, which does not provide position information natively. This is where Phil Harvey’s excellent program ExifTool comes in.
There are a lot of tools for dealing with image EXIF and GPS data, but ExifTool has two big things in its favor. First, you will not find a tool that is more full-featured or better able to work with EXIF data. Second, it is free and open-source. ExifTool is available for virtually any platform as both a Perl library and a standalone command-line utility. In many cases I prefer to use the command-line utility and that is what will be used for geotagging.
Of course, beyond the tool you will need an image or a set of images (in a directory) and a file containing your GPS data. The latter is most often in the form of a .gpx file. You might get this from your GPS unit via interface software (like GPSBabel) or you might make it yourself using other format logs. In my case, I have a text file of GPS information from my drone, written at 5Hz, and I wrote a python script to convert it to GPX. GPX is a simple xml derivative, so is easy to read and create.
Basic geotagging an entire directory of images with ExifTool is as simple as:
exiftool -geotag your-GPX-file.gpx /your/directory/images
To geotag only one image
exiftool -geotag your-GPX-file.gpx /dir/images/your-image.jpg
If you have GPS metadata, exiftool will overwrite it. If there were no GPS tags to begin with then exiftool will create them. There is also a
-geosync option for modifying the time in your image files to correct for clock offsets in your camera. The most common issue I run into is that the GeoTime tag is not set and without this the images cannot be geotagged. There is an easy fix for this as well. Just use the -geotime option.
exiftool -geotag file.gpx "-geotime<filemodifydate" -P imagedir
This will set the GeoTime tag to the file modify date, which is typically when the file was created. The -P preserves the original times and the -geosync option can be used after you have set the GeoTime.
I have only scratched the surface of what ExifTool can do, but hopefully enough to pique your interest. ExifTool is a great free program for various functions involving EXIF image metadata and I encourage folks to check it out at Phil Harvey’s page. For those interested in a much more detailed look at geotagging with ExifTool please look here.
As always, I hope this is useful to you and thank you for reading.