# Extract a GPS track (as .gpx) from a series of jpg photos

I have a bunch of `.jpg` photos containing GPS information. What is the easiest way to extract the GPS information and save it into a `.gpx` file (or `.kml`, for that matter)?

I have seen this answer pointing to `exiftool`, which gives a readable output, but I would like to import the track into other applications (e.g. Oruxmaps or Google Maps).
Answers to this question on gis.stackexchange.com point to Windows programs, but I am looking for a usable alternative on Mac OSX.

Exiftool is going to be the easiest way to do this.

Here is a script that generates KML output for a list of images. You can modify this if you want a KML path, etc…

``````#! /usr/bin/env python
# -*- coding: utf-8 -*-

"""
Create a KML file based on exif data

Requires exiftool to have been installed
Usage: exif2kml.py *.jpg > output.kml

"""

import os
import sys
import re
import time

def decimalat(DegString):
# This function requires that the re module is loaded
# Take a string in the format "34 56.78 N" and return decimal degrees
SearchStr=r''' *(\d+) deg (\d+)' ([\d\.]+)" (\w)'''
Result = re.search(SearchStr, DegString)

# Get the (captured) character groups from the search
Degrees = float(Result.group(1))
Minutes = float(Result.group(2))
Seconds = float(Result.group(3))
Compass = Result.group(4).upper() # make sure it is capital too

# Calculate the decimal degrees
DecimalDegree = Degrees + Minutes/60 + Seconds/(60*60)
if Compass == 'S' or Compass == 'W':
DecimalDegree = -DecimalDegree
return DecimalDegree

def writePlace(filename,lat,lon,date):
PlacemarkString = '''
<Placemark>
<name>{0}</name>
<Point>
<altitudeMode>absolute</altitudeMode>
<coordinates>{1}, {2}</coordinates>
<TimeStamp>
<when>{3}</when>
</TimeStamp>
</Point>
</Placemark>'''.format(filename,lat,lon,date)
return PlacemarkString

<Document>'''

if len(sys.argv)<2:
print >> sys.stderr, __doc__

else:
placestring = ''
FList = sys.argv[1:]
for F in FList:
ExifData=os.popen('exiftool "'+ F +'" -DateTimeOriginal -GPSLatitude -GPSLongitude').read()
if "Longitude" in ExifData:
print >> sys.stderr, F,"\n",ExifData.rstrip()
Fields = ExifData.split("\n")
for Items in Fields:
if len(Items)> 10:
K,V = Items.split(" : ")
if "Latitude" in K:
lat = decimalat(V)
elif "Longitude" in K:
lon = decimalat(V)
elif "Date" in K:
date = time.strptime(V.strip(),"%Y:%m:%d %H:%M:%S")  # time format
if lat:
TimeFmt = "%Y-%m-%dT%H:%M:%S"
placestring += writePlace(F,lon,lat,time.strftime(TimeFmt,date))
lat = ''
# Generate the output file...
# This just prints to screen -- use > to capture to file...