Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Last active August 20, 2023 15:39
Show Gist options
  • Save loisaidasam/3198a4289aff8538df4d67f62e1dab75 to your computer and use it in GitHub Desktop.
Save loisaidasam/3198a4289aff8538df4d67f62e1dab75 to your computer and use it in GitHub Desktop.
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).

Usage

$ ./image-distance.sh <filename.jpg>

Example:

./image-distance.sh 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 exif-gps.sh, which grabs some specific Exif metadata info from an image, using exiftool, formats the results, and uses them to call distance.py, which parses out the lat/lon strings and calculates the distance to the BofA building.

Requirements

Why?

... 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

-https://en.wikipedia.org/wiki/We_choose_to_go_to_the_Moon

#!/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" % latlon.lat
print "Longitude: %s" % latlon.lon
distance = distance_to_bofa(latlon)
print "Distance to BofA Building: %s km" % distance
#!/bin/bash
filename="$1"
if [ -z "$filename" ]
then
echo "Enter filename dep!"
exit 1
fi
# 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
#!/bin/bash
# Use this file to get from image -> exif lat/lon -> distance
filename="$1"
echo "Filename: $filename"
lat=$(./exif-gps.sh "$filename" | cut -d':' -f2 | head -n1)
lon=$(./exif-gps.sh "$filename" | cut -d':' -f2 | tail -n1)
./distance.py "$lat" "$lon"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment