Fortes


Command-line photo geotagging

Using Google location data in order to geotag photographs from a camera via the command-line

Compass rose and mappa mundi at the Padrão dos Descobrimentos

Compass rose and mappa mundi at the Padrão dos Descobrimentos Lisbon, Portugal

In our last installment, I walked through the steps I took to get “good enough” filesystem layout for my multi-decade digital photo collection. I’ve since uploaded everything to Google Photos and have been pretty happy with how things work.

One nice feature Google Photos provides is the ability to easily search photos by geographic location. Their system is smart enough to grab a bunch of metadata based on the GPS coordinates. If you’ve given into the cloud, you can try this yourself by searching some location names. They support city, state/province, and country; they also seem to support a limited set of finer-grained locations such as universities or airports.

Google Photos suggesting geographic search queries

Of course, this only works if your photos have been geotagged (although Google can sometimes estimate your location even without GPS coordinates). Photos taken on the phone camera will pretty much always have GPS data (unless manually disabled), so the vast majority of my photos are already correctly tagged.

However, I still lug around a non-phone camera every once in a while, but unfortunately not one of the few GPS-enabled cameras so I continue to generate untagged files and bring shame upon my family. I’m pretty obsessive about metadata, but I’m not dropping a bunch of money on a new camera just get to GPS tags.

It’s tempting to settle for Google’s automatic location detection, but I’ve learned to hedge my bets ever since they broke my heart by killing Google Reader.

Fortunately, Google’s frighteningly effective panopticon can be tapped for our needs in this situation. If you’re never checked out your Google Maps Timeline, you may be shocked at how thoroughly your geographic past has been preserved. Fortunately, we use this to our advantage in order to annotate our non-smartphone images (this is almost certainly the same data used to estimate location in Google Photos). Within your timeline, you can export your coordinates to a KML file.

Exporting a trackfile from Google Timeline

Once you’ve downloaded that KML file, you can use our metadata Swiss Army knife Exiftool to automatically geotag all your photos from that day:

# Warning: Updates metadata and overwrites original files
exiftool -overwrite_original_in_place -geotag history-2017-09-27.kml -r images/*

Unfortunately, there is no API for the Google Maps Timelines, so you have to repeat this process manually for each day you’re looking to process photos from. Alternatively, you can export your entire history, but it takes a while before you get all the files.

Once again, we’ve found a nerdy, cumbersome, and partial solution to a problem well-adjusted humans spend zero time thinking about. Success!