#!/bin/bash
# usage:
#   jpg2gps picture.jpg
#
# print EXIF GPS coordinates (CSV) of picture

if [ $# -ne 1 ]; then
  echo 'Syntax: jpg2gps picture.jpg'
  exit
fi

image=$1

sizex=$2
sizey=$3

options=

# get GPS coords

# substring matching
# gpsx=`jhead "$image" | grep "^GPS Latitude :" | sed "s/GPS Latitude :\(.*\), \(.*\)/\1/g"`

gpsx=`jhead "$image" | grep "^GPS Latitude : " | cut -b 16- | tr -d " \r\n"`
gpsy=`jhead "$image" | grep "^GPS Longitude: " | cut -b 16- | tr -d " \r\n"`
#gpsa=`jhead "$image" | grep "^GPS Altitude : " | cut -b 16- | tr -d " \r\n"`

# Prfix nach hinten
gpsxd=`echo $gpsx | cut -b -1`
gpsyd=`echo $gpsy | cut -b -1`
gpsx=`echo $gpsx | cut -b 2-`$gpsxd
gpsy=`echo $gpsy | cut -b 2-`$gpsyd

echo "$gpsx $gpsy" | tr "ms" "\'\"" | \
cs2cs  +proj=longlat +datum=WGS84 +to +proj=longlat +datum=WGS84 -f "%.8f" -s | \
cut -d " " -f 1 | tr "\t" ","

