Skip to content

Instantly share code, notes, and snippets.

@bijanebrahimi
Created September 10, 2014 16:40
Show Gist options
  • Save bijanebrahimi/5f316fc0125785ab6246 to your computer and use it in GitHub Desktop.
Save bijanebrahimi/5f316fc0125785ab6246 to your computer and use it in GitHub Desktop.
Geolocation meta data convertor (degree to decimal)
#!/bin/bash
# Geolocation meta data convertor (degree to decimal)
# Authur: Bijan Ebrahimi
# License: GPL v3.0 or any later
if [ ! "$#" == "1" ]; then
echo "Manual: `basename $0` JPG_FILE"
exit 1
fi
if [ ! -e "/usr/bin/exif" ]; then
echo "You need to install the 'exif' command first"
echo "(in Debian run: sudo apt-get install exif)"
exit 1
fi
if [ ! -e "/usr/bin/bc" ]; then
echo "You need to install the 'bc' command first"
echo "(in Debian run: sudo apt-get install bc)"
exit 1
fi
fn="$1"
long_=$(exif $fn | grep "Longitude")
lat_=$(exif $fn | grep "Latitude")
lon=0;
counter=0;
echo $long_ | grep -o "[0-9\.]\+" | while read deg; do
lon=$(echo "scale=15; $lon + ($deg / (60^$counter))" | bc);
counter=$(echo "$counter+1" | bc);
if [ "$counter" == "2" ]; then
echo -n "Lat: $lon"
fi
done;
lat=0;
counter=0;
echo $lat_ | grep -o "[0-9\.]\+" | while read deg; do
lat=$(echo "scale=15; $lat + ($deg / (60^$counter))" | bc);
counter=$(echo "$counter+1" | bc);
if [ "$counter" == "2" ]; then
echo " Lon: $lat"
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment