Geotagging photos in two commands
This is quite possibly the coolest and easiest thing that I’ve done in a while with my “content”. I took a bunch of photos while in Zion last week and I happened to be simultaneously taking a GPS track. Seems like the two should be able to augment each other, especially when several apps like Google’s Picasa allow you to display your photos on a map if they have location information.
But I just had a crappy point and shoot camera, w/o a GPS module on it. So I was envisioning some way of querying the database for the proper time for each image and then editing the EXIF tags. It would have been a little monotonous, but at least would have been more accurate than placing each photo on a map manually.
select y(wkb_geometry) || ', ' || x(wkb_geometry), diff from track_points natural join (select ogc_fid, time - (timestamp '2012-11-18 07:17:38' - interval '63 minutes' - interval '35 seconds') as diff from track_points) foo where diff < interval '120 seconds' and diff > '-120 seconds';
Well, it turns out that Picasa sucks, and even if you type in the proper lat/lon coordinates into the “location information” text box, it moves your photo to the nearest road! What the hell?! I’m not taking photos from a road! indignation
Fortunately, Picasa’s brokeness forced me to find a more elegant solution. Thinking that I would have to write a dumb shell script, I just happened to be reading the man page for exiftool and happened upon the -geotag option. That sounds promising. Turns out that it can take a gpx as input, can take a time offset to handle a camera being out of sync with GPS time, and can scan a directory doing all images at once! Everything I need! Let’s see here…
james@granite:~/data/gps/ut/201211$ ogr2ogr -where "time > '2012-11-17'" -f gpx zion.gpx "PG:dbname='spatial2' host='basalt.pcic.uvic.ca'"
james@granite:~/Pictures$ exiftool -geotag ~/data/gps/ut/201211/zion.gpx -geosync=-1:03:35 201211_zion/ Warning: Time is too far from nearest GPS fix in File:Geotime (ValueConvInv) - 201211_zion/IMGP6623.JPG Warning: No writable tags found - 201211_zion/IMGP6623.JPG Warning: Time is too far before track in File:Geotime (ValueConvInv) - 201211_zion/IMGP6582.JPG Warning: No writable tags found - 201211_zion/IMGP6582.JPG Warning: Time is too far from nearest GPS fix in File:Geotime (ValueConvInv) - 201211_zion/IMGP6622.JPG Warning: No writable tags found - 201211_zion/IMGP6622.JPG Warning: Time is too far before track in File:Geotime (ValueConvInv) - 201211_zion/IMGP6581.JPG Warning: No writable tags found - 201211_zion/IMGP6581.JPG Warning: Time is too far before track in File:Geotime (ValueConvInv) - 201211_zion/IMGP6578.JPG Warning: No writable tags found - 201211_zion/IMGP6578.JPG Warning: Time is too far before track in File:Geotime (ValueConvInv) - 201211_zion/IMGP6580.JPG Warning: No writable tags found - 201211_zion/IMGP6580.JPG Warning: Time is too far from nearest GPS fix in File:Geotime (ValueConvInv) - 201211_zion/IMGP6620.JPG Warning: No writable tags found - 201211_zion/IMGP6620.JPG Warning: Time is too far before track in File:Geotime (ValueConvInv) - 201211_zion/IMGP6583.JPG Warning: No writable tags found - 201211_zion/IMGP6583.JPG Warning: Time is too far from nearest GPS fix in File:Geotime (ValueConvInv) - 201211_zion/IMGP6624.JPG Warning: No writable tags found - 201211_zion/IMGP6624.JPG Warning: Time is too far from nearest GPS fix in File:Geotime (ValueConvInv) - 201211_zion/IMGP6619.JPG Warning: No writable tags found - 201211_zion/IMGP6619.JPG Warning: Time is too far before track in File:Geotime (ValueConvInv) - 201211_zion/IMGP6579.JPG Warning: No writable tags found - 201211_zion/IMGP6579.JPG Warning: Time is too far from nearest GPS fix in File:Geotime (ValueConvInv) - 201211_zion/IMGP6621.JPG Warning: No writable tags found - 201211_zion/IMGP6621.JPG 1 directories scanned 137 image files updated 12 image files unchanged
And with that, voila!
There are a bunch of warnings there, because I took a handful of photos during times when I wasn’t running the GPS (or I lost the track, due to lack of memory). But aside from those 12 images, in two commands, I was able to geotag 137 images with location information. That, I must say, is one of my most satisfying bedtime hacks in a while.
blog comments powered by Disqus