Skip to content

Geo-tag Photographs

I discovered that it is possible to add GPS coordinates to the EXIF data in any JPEG image. Generally this info can come from anywhere, but I’m interested in using track log data from my Garmin GPS III to syncronize to photos taken while the GPS was active.

This breaks down into the following

  1. Track/Waypoint Data Collection
  2. Data Download(Track/WayPoint and Photo)
  3. Image Geotaging
  4. Google Earth kml/kmz generation

I first did this with “windows” tools, but have migrated to cmd line linux friendly tools

  1. Track/Waypoint Data Collection
  2. Verify the camera’s date/time is set. Before starting your hike/trip reset the active track log, and enable tracking.
    Start your hike, taking pictures along the way. At the completion of your hike, stop active tracking before turning off the GPS.
    Do not save the active track log

    TIP: Take a picture of the GPS’s time at the start and end of your hike.

  3. Data Download(Track/WayPoint and Photo)
  4. Create a directory for your images. Connect the GPS to the computer with the serial data cable. Change to the image directory, download track data with gpsbabel.

    gpsbabel.exe -t -i garmin -f COM1: -o gpx -F Hike.gpx
    At this point the downloaded track(s) should be examined graphicly. I use EasyGPS to determine where bad GPS data was and then hand delete them with a text editor

    Rotate Portrait Photos:
    Before downloading first rotate photos to the correct orientation on your camera.

    Download Todays Photos:
    Using unix find to move photos, connect camera or Media to computer.
    find I: -mtime -0 -name CIMG\* -exec mv -u '{}' . \;

    Rotate Images to Correct orientation
    Use jhead to auto rotate photos.
    jhead -autorot CIMG*.JPG

    Now examine all photos an delete any bad ones.

    Correct photo’s Time
    Examine the gps clock photo for the time and compare to the time stamped on the photo. Correct all photos time with(25 sec)
    jhead -ta-0:0:25 CIMG????.JPG
    Now correct the file timestamp of the photos
    jhead -ft CIMG????.JPG

  5. Image Geotaging
  6. Create a time sorted file list of the photos.
    ls -1rt CIMG*.JPG >photos.txt

    First just tag the geo coordinates of the files with -I photos.txt --gpsfile hike.gpx --interpolate=linear --report-distance=miles --report-direction=8 -timeoffset=25200

    Now add a few tags with exiftool
    exiftool -ImageDescription="hike of my backyard" -city="Fremont" -Province-State=California -Country-PrimaryLocationName="United States" -sub-location="Someplace" -artist="Joel C. Schantz" -Copyright="Joel C. Schantz" CIMG????.JPG

    if you have a photo that is not taggable from the track log you can also geotag it with exiftool. Determine the lat/lon and tag with
    exiftool -ObjectName="Park Entrance" -GPSLatitude=37.817965 -GPSLatitudeRef=N -GPSLongitude=121.795968 -GPSLongitudeRef=W -GPSAltitude=0 -GPSAltitudeRef="Above Sea Level" CIMG7031.JPG

    Also add a valid GPS time date with
    exiftool -GPSDateStamp=2008:05:12 -GPSTimeStamp=17:38:42 CIMG7031.JPG

    Note: exiftool creates backups that should be removed.
    \rm rm *original

    Verify the time deltas for each picture are correct, and open the doc.kml or test.kml file in google earth to verify.

  7. Google Earth kml/kmz generation
  8. Now the default images can be a bit large, so we make some smaller ones and some thumbnails.
    First a function to resize and watermark

    resize () {
     convert $1 -resize 1024x1024 /cygdrive/e/Images/WM2008.png -gravity SouthEast -compose overlay -composite  -quality 85 ${1##*/} ;

    And also function to create thumbnails from those photos.

    thumbit () {
     convert $1 -resize 128x128 -quality 85 thumbs/${1##*/} ;

    now create a resized directory and go there
    mkdir resized ; cd resized
    Now resized the photos

    for x in ../CIMG????.JPG ; do if [ ! -f ${x##*/} ] ; then resize $x ; fi ; done

    At this point I usually try and reduce the number of photos for the track to less than 100.

    You can now create the thumbnails.

    mkdir thumbs;
    for x in CIMG????.JPG ; do if [ ! -f thumbs/${x##*/} ] ; then thumbit $x ; fi ; done

    Now regenerate a photo list.
    ls -1rt CIMG*.JPG >photos.txt

    and create your kml file. -I photos.txt --gpsfile ../hike.gpx --kml Myhike.kml --track-color static6 --interpolate=linear -n

    Now I have been hand editing this file to change the name and description fields. This file must also be changed to use the thumbnails and to prepare it to be served from a web page.

    First test the kml file by generating a local version with sed.

    sed -e 's|\(<icon><href>\)|\1thumbs/|g' Myhike.kml >test.kml

    Examine with Google Earth, if OK create a kmz version to be hosted from my comcast web with

    /cygdrive/e/Images/ photos.txt CoyoteHills >cc.sed
    sed -f cc.sed MyHike.kml >HikeCC.kml
    zip -o Hike.kmz HikeCC.kml

Another geotagging example technique: --dir "E:/Images/Alameda Creek/small" \
--gpsfile trip.gpx --kml test.kml -timeoffset=guess-37 \
--tz-guess 15deg --track-color static6 --interpolate=linear \
--report-distance=miles --report-direction=8 --city Niles \
--sublocation auto  --state auto --country auto --credit "Joel C. Schantz"

Some of the location names(city, sublocation) may not be optimal, so just substitute real names for auto.
Also for a single geo location(without a gpx file) use
–geotag-source=option –geotag=lat,long,elevation

EX: –geotag-source=option –geotag=37.559116,-122.004459,0


No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: