-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgpslog2exif.sh
executable file
·131 lines (109 loc) · 4.52 KB
/
gpslog2exif.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /bin/bash
#David Shean
#11/4/13
#Use csv or gpx GPS log from to geotag a directory full of photos
#Requires exiftool, gpsbabel, ogr/gdal
#Must set offsets manually
#Note: want to set exiftool to limit GeoMaxExtSecs in ~/.ExifTool_config
#This prevents extrapolation across gaps in GPS log
#Need to implement HDOP filter
#Need to prevent GPSMapDatum from being updated when geotagging with TPO GPS log doesn't occur (no overlap)
#Tested with input csv from Trimble Pathfinder Office
#Use preset csv_geoxh_ptlog
#"Configurable ascii"
#Positions only - One point per GPS position
#CSV template (note: NO {GPS Time})
#{Feature ID} {Latitude} {Longitude} {HAE} {Attributes}
#Check "use template as header"
#NOTE: Apparently, we need to use "Date recorded" and "Time recorded" output from TPO
#This was ~7 seconds earlier than the recorded GPS Time for each point in the 20130716 Greenland hike
#This syncs with the Nikon GP-1 GPS timestamps
exif2shp=/Users/dshean/src/sfm/exif2gpslog.sh
echo
if [ $# -ne 2 ] ; then
echo "Usage is $0 tpo.[csv,gpx] photodir"
echo
exit 1
fi
in_fn=$1
photo_dir=$2
#Copy the TPO csv to photo directory as a record
rsync -av --progress $in_fn $photo_dir
#Timezone offset of exif DateTimeOriginal relative to UTC
#Should be 0 when camera clock is properly set to UTC (with daylight savings off)
tz="-00:00"
#This is the value needed for Greenland 2013 images (doh!)
#tz="-02:00"
#For 20130509 flight
#tz="-07:00"
#For 20130910 flight
#tz="-07:00"
#This is the offset between the camera clock and GeoXH GPS time, should only be a few seconds
#From exiftool doc:
#This time difference may be of the form "SS", "MM:SS", "HH:MM:SS" or "DD HH:MM:SS" (where SS=seconds, MM=minutes, HH=hours and DD=days), and a leading "+" or "-" may be added for positive or negative differences (negative if the camera clock was ahead of GPS time). Fractional seconds are allowed (eg. "SS.ss").
#geosync_offset=0.0
#20130910_Cascades
#geosync_offset=3.0
#20140914_Cascades
#geosync_offset=0.25
#Mammoth survey
#geosync_offset=-0.5
#20130509 Rainier flight
#geosync_offset=+0.5
#201207 fieldwork
#geosync_offset=+3.0
#20140808 baker NEX-5 UAV flights
#geosync_offset=-1.0
#20141005 baker NEX-5 UAV flights
geosync_offset=67.8
#Use SubSec times if they are available
firstphoto=$(ls $photo_dir | head -1)
if [[ -n $(exiftool -SubSecTimeOriginal $firstphoto) ]]; then
subsec=true
else
subsec=false
fi
#Output original photo locations as shp
#Note: this will update GPSAltitude to HAE if not already done
if [ "$(exiftool -GPSLatitude $photo_dir | grep 'GPS' | wc -l)" -gt "2" ]; then
echo "Generating shp from original photo exif data"
out=exif_coord_original
echo $exif2shp $photo_dir $out
$exif2shp $photo_dir $out
fi
#Convert TPO csv gps log to gpx (currently required by exiftool)
gpx_fn=${in_fn%.*}.gpx
if [ ! -e $gpx_fn ] ; then
#ogr2ogr -f GPX -dsco GPX_USE_EXTENSIONS=yes $gpx_fn $shp_fn
echo "Converting $in_fn to $gpx_fn"
#Assuming TPO output (csv) has header with standard field names, the following will work
#utc=0 is required to set GPS time zone to UTC, not local time zone
#-t creates a track instead of waypoints
gpsbabel -t -i unicsv,utc=0 -f $in_fn -o GPX -F $gpx_fn
fi
echo
echo "Updating geotagging in $photo_dir (and updating GPSMapDatum, which requires backup)"
#Want to update the datum, since TPO positions are all HAE
#Need some way to only do this for images that are actually geotagged here
#Note: when gpx log times don't overlap, this gives
# Warning: No writable tags set from ./DSC_9460.NEF
#Use Original DateTime with Subsecond (precision 0.1 s for D800) time in exif header
if $subsec ; then
exiftool -progress -fileOrder DateTimeOriginal -Geotag $gpx_fn -Geosync=$geosync_offset "-Geotime<\${SubSecDateTimeOriginal}${tz}" -GPSMapDatum='WGS 84 HAE' $photo_dir
else
exiftool -progress -fileOrder DateTimeOriginal -Geotag $gpx_fn -Geosync=$geosync_offset "-Geotime<\${DateTimeOriginal}${tz}" -GPSMapDatum='WGS 84 HAE' $photo_dir
fi
#Could also use GPSDateTime, but not all images have valid GPS info from Nikon GP-1
#"-Geotime<GPSDateTime"
#The exiftool doc describes a way to use certain photos as tiepoints for -Geosync
#Should be able to script this to use all available exif GPS times
#Move original jpg to subfolder
#mkdir $photo_dir/original
#mv $photo_dir/*.*_original $photo_dir/original
#Output corrected photo locations as shp
echo
echo "Generating shp from updated photo exif data"
out=exif_coord_corrected
echo $exif2shp $photo_dir $out
$exif2shp $photo_dir $out