Skip to content

Instantly share code, notes, and snippets.

Last active September 20, 2017 03:39
What would you like to do?
Image EXIF Distance Tools

Image EXIF Distance Tools

Some scripts for finding the distance between the location of an image and the Bank of America Building in Atlanta (or maybe you have a better use-case).


$ ./ <filename.jpg>


./ images/IMG_20170913_083501.jpg 
Filename: images/IMG_20170913_083501.jpg
Latitude: 33.7660111111
Longitude: -84.3974111111
Distance to BofA Building: 0.948619993884 km

Under the hood, this makes calls to, which grabs some specific Exif metadata info from an image, using exiftool, formats the results, and uses them to call, which parses out the lat/lon strings and calculates the distance to the BofA building.



... because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one we intend to win


#!/usr/bin/env python
import sys
import LatLon
LATLON_BOFA = LatLon.LatLon(33.7706862, -84.3888361)
def get_exif_latlon(lat, lon):
Where lat/lon are strings like:
- "33 deg 45' 57.64\" N"
- "84 deg 23' 50.68\" W"
return LatLon.string2latlon(lat, lon, "d% deg %m%' %S%\" %H")
def distance_to_bofa(latlon):
return latlon.distance(LATLON_BOFA)
if __name__ == '__main__':
lat, lon = sys.argv[1:]
latlon = get_exif_latlon(lat, lon)
print "Latitude: %s" %
print "Longitude: %s" % latlon.lon
distance = distance_to_bofa(latlon)
print "Distance to BofA Building: %s km" % distance
if [ -z "$filename" ]
echo "Enter filename dep!"
exit 1
# Just grepping for "GPS L" would yield the following:
# GPS Longitude Ref : West
# GPS Latitude Ref : North
# GPS Latitude : 33 deg 45' 49.37" N
# GPS Longitude : 84 deg 21' 24.34" W
exiftool "$filename" |grep "GPS L" |grep -v Ref
# Use this file to get from image -> exif lat/lon -> distance
echo "Filename: $filename"
lat=$(./ "$filename" | cut -d':' -f2 | head -n1)
lon=$(./ "$filename" | cut -d':' -f2 | tail -n1)
./ "$lat" "$lon"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment