Consider them as feature requests? Do you have an issue tracker so that these will not be forgotten.
| The Following User Says Thank You to Framstag For This Useful Post: | ||
#!/bin/bash
#
# Fix a gpsjinni file that has swapped latitude/longitude information.
#
USAGE='Usage: fixjinni kml-files'
TMP=/tmp/fixjinni.$$
trap "rm -f $TMP; exit 1" 1 2 15
trap "rm -f $TMP; exit 0" 13
for file
do
awk '{
if ($1 == "</coordinates>")
{
incoords = 0
print
}
else if ($0 ~ /<coordinates>/)
{
gt = index($0, ">")
prefix = substr($0, 1, gt)
suffix = substr($0, gt + 1)
if (suffix == "")
{
incoords = 1
print
next
}
lt = index(suffix, "<")
coords = substr(suffix, 1, lt - 1)
suffix = substr(suffix, lt)
split(coords, data, ",")
print prefix data[2] "," data[1] "," data[3] suffix
}
else if (incoords)
{
split($1, data, ",")
print " " data[2] "," data[1] "," data[3]
}
else
print
}' \
"$file" \
> $TMP
(trap "" 1 2 13 15; cp $TMP "$file")
rm -f $TMP
done
#!/bin/bash
#
# Fix geotags that were incorrectly input by gpsjinni. This code
# depends on the assumption that I'm beyond 90 degrees either east or
# west.
#
USAGE="Usage: geotagfix [-m maxlat] [-v] files
The given files have their GPS data extracted. The latitudes and
longitudes are interchanged, and the files are rewritten with the new
data.
-m maxlat Specify the (integer) maximum latitude found anywhere
in the files (default 0). Only images with
"latitudes" greater than this value will be rewritten.
For example, if you are shooting in most of the United
States, specify -l 90 to only swap pictures that have
a latitude greater than or equal to 90 degrees (which is
impossible in a correct file). The default, -m 0,
will swap the coordinates in all files; in this case
you must ensure that all input files actually need
correction.
-n Report files that would be fixed, but don't fix them.
-v Report changed files."
maxlat=0
action=true
verbose=false
while (( $# > 0 ))
do
case "$1" in
-m)
maxlat="$2"
shift
;;
-n)
action=false
;;
-v)
verbose=true
;;
--)
shift
break
;;
-*)
echo "$USAGE" 1>&2
exit 2
;;
*)
break
;;
esac
shift
done
TMP=/tmp/geotagfix.$$
trap "rm -f $TMP.*; exit 1" 1 2 15
trap "rm -f $TMP.*; exit 0" 13
for pic
do
case "$pic" in
*.jpg|*.cr2)
;;
*)
continue
;;
esac
exiftool "$pic" \
| egrep GPS \
| sed '/^GPS Date/s/:/-/g' \
> $TMP.a
lat=$(grep 'GPS Latitude *:' $TMP.a | awk '{print $4}')
if (( lat >= $maxlat ))
then
# Picture needs coordinate swapping. Since exiftool refuses to
# let us rewrite GPS tags, we need to create a dummy KML file
# and use it to geotag the picture.
#latref=$(sed -n 's/GPS Longitude Ref *: *//p' $TMP.a)
#longref=$(sed -n 's/GPS Latitude Ref *: *//p' $TMP.a)
awk '
/^GPS Time / \
{
tm = $NF
}
/^GPS Date / \
{
dt = $NF
}
/^GPS Altitude / \
{
alt = $4
}
/^GPS Latitude / \
{
# This is actually the longitude. We take advantage
# of the fact that if you add zero to a string, awk
# converts it to a number while ignoring any trailing
# non-numeric information (in this case, single and
# double quotes).
d = $4
m = $6 + 0
s = $7 + 0
dir = $8
long = d + m / 60.0 + s / 3600.0
if (dir == "S")
long = -long
}
/^GPS Longitude / \
{
# This is actually the latitude. See above about awk
# numeric conversions.
d = $4
m = $6 + 0
s = $7 + 0
dir = $8
lat = d + m / 60.0 + s / 3600.0
if (dir == "W")
lat = -lat
}
END \
{
# Make a fake GPX file to feed to exiftool. I was
# originally making a KML file, but in the process of
# working around the exiftool bug I switched to GPX
# and I was too lazy to switch back (especially
# because GPX is simpler).
print "<?xml version=\"1.0\"?>"
print "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ec=\"eCoachGPXExtensionsV1\" version=\"1.1\" creator=\"ecoach\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd eCoachGPXExtensionsV1 /usr/share/ecoach/ec_gpx_ext_v1.xsd\">"
print "<trk>"
print "<name>Dummy</name>"
print "<number>1</number>"
print "<trkseg>"
printf "<trkpt lat=\"%.12f\" lon=\"%.12f\">\n", lat, long
printf "<ele>%.4f</ele>\n", alt
printf "<time>%sT%sZ</time>\n", dt, tm
print "</trkpt>"
# A bug in exiftool requires at least two track points
# with different times, else you get a divide by zero.
# We hack this by faking a time far in the future.
printf "<trkpt lat=\"%.12f\" lon=\"%.12f\">\n", lat, long
printf "<ele>%.4f</ele>\n", alt
print "<time>2038-01-01T00:00:00Z</time>"
print "</trkpt>"
print "</trkseg>"
print "</trk>"
print "</gpx>"
}' \
$TMP.a \
> $TMP.gpx
if $action
then
exiftool -q -overwrite_original -geotag $TMP.gpx "$pic"
$verbose && echo "Fixed $pic"
else
echo "$pic needs fixing."
fi
fi
done
rm -f $TMP.*
--- GPSJinni.cpp.orig 2010-09-27 16:22:37.000000000 +1300
+++ GPSJinni.cpp 2010-09-27 16:28:26.000000000 +1300
@@ -1594,7 +1594,8 @@
alt=falt/100;
time.SetTime(ftim);
- out << " " << lon << "," << lat << "," << alt << std::endl;
+ out << " " << setprecision(8) << lat << "," << lon;
+ out << "," << setprecision(3) << alt << std::endl;
}
}