Package: gpscorrelate / 1.6.1-7

70-option-overwrite-gpstags.patch Patch series | download
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
Description: Add ability to force overwriting of existing tags.
Author: Toby Speight <T.M.Speight.90@cantab.net>
Bug: https://bugs.debian.org/683772
Last-Update: 2018-04-05
--- a/correlate.c
+++ b/correlate.c
@@ -60,7 +60,7 @@
 		Options->Result = CORR_NOEXIFINPUT;
 		return 0;
 	}
-	if (IncludesGPS)
+	if (IncludesGPS && !Options->OverwriteExisting)
 	{
 		/* Already have GPS data in the file!
 		 * So we can't do this again... */
--- a/correlate.h
+++ b/correlate.h
@@ -29,6 +29,7 @@
  * Not really sure if this is needed, but... */
 struct CorrelateOptions {
 	int NoWriteExif;
+	int OverwriteExisting;
 	int NoInterpolate;
 	int NoChangeMtime;
 	int TimeZoneHours;  /* To add to photos to make them UTC. */
--- a/doc/command.html
+++ b/doc/command.html
@@ -54,6 +54,13 @@
 
 <tr>
 <td valign="top" nowrap="nowrap">
+<b>--force or -F</b>
+</td><td>
+Overwrite any existing GPS EXIF tags in the file. Without this option, image files that already have GPS tags are not modified.  Setting this option will never cause tags to be removed; use -r for that.
+</td></tr>
+
+<tr>
+<td valign="top" nowrap="nowrap">
 <b>--datum or -d "datum"</b>
 </td><td>
 Specifies the "datum" to write into the GPS EXIF tags. By default, it is WGS-84. However, GPX is not supposed to store anything but WGS-84, so use if you must.
--- a/doc/gpscorrelate-manpage.xml.in
+++ b/doc/gpscorrelate-manpage.xml.in
@@ -77,6 +77,11 @@
         <arg choice="plain">-n</arg>
         <arg choice="plain">--no-write</arg>
       </group>
+      
+      <group>
+        <arg choice="plain">-F</arg>
+        <arg choice="plain">--force</arg>
+      </group>
 
       <group>
         <arg choice="plain">-m</arg>
@@ -297,6 +302,16 @@
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>
+          <option>-F</option>,
+          <option>--force</option>
+        </term>
+        <listitem>
+          <para>overwrite existing GPS tags</para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>
           <option>-m</option>,
--- a/doc/gui.html
+++ b/doc/gui.html
@@ -28,6 +28,8 @@
 
 <p>The <b>"Don't write"</b> checkbox, if checked, will prevent the GPS EXIF tags being written back to the photo. However, the point that is matched will be shown in the list, which allows you to correlate and check the results first.</p>
 
+<p>The <b>"Overwrite existing tags"</b> checkbox, if checked, will make matches replace any existing tags.  Without this option, files that already have GPS tags will not be touched.  Unmatched files will not be modified, regardless of this setting.</p>
+
 <p>The <b>"Don't change mtime"</b> checkbox, if checked, will prevent changes to the JPEG files from updating the files mtime.</p>
 
 <p>The <b>"Between Segments"</b> checkbox, if checked, will ignore track segments, and match photos between track segments. Usually a track segment differentiates between multiple GPS data logging sessions, so interpolating between track segments could well be interpolating when there was no GPS data.</p>
--- a/exif-gps.cpp
+++ b/exif-gps.cpp
@@ -434,6 +434,15 @@
 
 }
 
+void replace(Exiv2::ExifData &exif, Exiv2::ExifKey key, const Exiv2::Value *value)
+{
+    Exiv2::ExifData::iterator it = exif.findKey(key);
+    if (it != exif.end())
+        it->setValue(value);
+    else
+        exif.add(key, value);
+}
+
 int WriteGPSData(char* File, struct GPSPoint* Point, char* Datum, int NoChangeMtime, int DegMinSecs)
 {
 	// Write the GPS data to the file...
@@ -473,7 +482,7 @@
 	//  (and, must be present).
 	Exiv2::Value::AutoPtr Value = Exiv2::Value::create(Exiv2::unsignedByte);
 	Value->read("2 0 0 0");
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID"), Value.get());
 	// Datum: the datum of the measured data. If not given, we insert WGS-84.
 	ExifToWrite["Exif.GPSInfo.GPSMapDatum"] = Datum;
 	
@@ -488,7 +497,7 @@
 	} else {
 		Value->read("1");
 	}
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSAltitudeRef"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSAltitudeRef"), Value.get());
 	// And the actual altitude.
 	Value = Exiv2::Value::create(Exiv2::unsignedRational);
 	ConvertToRational(fabs(Point->Elev), &Nom, &Denom, 4);
@@ -496,7 +505,7 @@
 
 	/* printf("Altitude: %f -> %s\n", Point->Elev, ScratchBuf); */
 	Value->read(ScratchBuf);
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSAltitude"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSAltitude"), Value.get());
 	
 	// LATTITUDE
 	// Latitude reference: "N" or "S".
@@ -548,7 +557,7 @@
 		snprintf(ScratchBuf, 100, "%ld/1 %ld/100 0/1", Deg, Min);
 	}
 	Value->read(ScratchBuf);
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSLatitude"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSLatitude"), Value.get());
 	
 	// LONGITUDE
 	// Longitude reference: "E" or "W".
@@ -595,7 +604,7 @@
 		snprintf(ScratchBuf, 100, "%ld/1 %ld/100 0/1", Deg, Min);
 	}
 	Value->read(ScratchBuf);
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSLongitude"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSLongitude"), Value.get());
 
 	// The timestamp.
 	// Make up the timestamp...
@@ -623,7 +632,7 @@
 			TimeStamp.tm_hour, TimeStamp.tm_min,
 			TimeStamp.tm_sec);
 	Value->read(ScratchBuf);
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSTimeStamp"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSTimeStamp"), Value.get());
 
 	// And we should also do a datestamp.
 	snprintf(ScratchBuf, 100, "%04d:%02d:%02d",
--- a/gui.c
+++ b/gui.c
@@ -71,6 +71,7 @@
 GtkWidget *OptionsVBox;
 GtkWidget *InterpolateCheck;
 GtkWidget *NoWriteCheck;
+GtkWidget *OverwriteCheck;
 GtkWidget *NoMtimeCheck;
 GtkWidget *BetweenSegmentsCheck;
 GtkWidget *DegMinSecsCheck;
@@ -324,6 +325,12 @@
   gtk_tooltips_set_tip (tooltips, NoWriteCheck, "Don't write EXIF data back to the photos.", NULL);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (NoWriteCheck), g_key_file_get_boolean(GUISettings, "default", "dontwrite", NULL));
 
+  OverwriteCheck = gtk_check_button_new_with_mnemonic ("Overwrite existing tags");
+  gtk_widget_show (OverwriteCheck);
+  gtk_box_pack_start (GTK_BOX (OptionsVBox), OverwriteCheck, FALSE, FALSE, 0);
+  gtk_tooltips_set_tip (tooltips, OverwriteCheck, "Overwrite any existing GPS tags in the photos.", NULL);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (OverwriteCheck), g_key_file_get_boolean(GUISettings, "default", "force", NULL));
+
   NoMtimeCheck = gtk_check_button_new_with_mnemonic ("Don't change mtime");
   gtk_widget_show (NoMtimeCheck);
   gtk_box_pack_start (GTK_BOX (OptionsVBox), NoMtimeCheck, FALSE, FALSE, 0);
@@ -545,6 +552,7 @@
 	/* Record the settings, and then save them. */
 	g_key_file_set_boolean(GUISettings, "default", "interpolate", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(InterpolateCheck)));
 	g_key_file_set_boolean(GUISettings, "default", "dontwrite", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(NoWriteCheck)));
+	g_key_file_set_boolean(GUISettings, "default", "overwrite", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(OverwriteCheck)));
 	g_key_file_set_boolean(GUISettings, "default", "nochangemtime", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(NoMtimeCheck)));
 	g_key_file_set_boolean(GUISettings, "default", "betweensegments", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(BetweenSegmentsCheck)));
 	g_key_file_set_boolean(GUISettings, "default", "writeddmmss", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(DegMinSecsCheck)));
@@ -552,7 +560,9 @@
 	g_key_file_set_string(GUISettings, "default", "timezone", gtk_entry_get_text(GTK_ENTRY(TimeZoneEntry)));
 	g_key_file_set_string(GUISettings, "default", "photooffset", gtk_entry_get_text(GTK_ENTRY(PhotoOffsetEntry)));
 	g_key_file_set_string(GUISettings, "default", "gpsdatum", gtk_entry_get_text(GTK_ENTRY(GPSDatumEntry)));
-	g_key_file_set_string(GUISettings, "default", "gpxopendir", GPXOpenDir);
+        if (GPXOpenDir)
+            g_key_file_set_string(GUISettings, "default", "gpxopendir", GPXOpenDir);
+        if (PhotoOpenDir)
 	g_key_file_set_string(GUISettings, "default", "photoopendir", PhotoOpenDir);
 	SaveSettings();
 
@@ -1082,6 +1092,14 @@
 		Options.NoWriteExif = 0;
 	}
 
+	/* Force overwrite. */
+	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(OverwriteCheck)))
+	{
+		Options.OverwriteExisting = 1;
+	} else {
+		Options.OverwriteExisting = 0;
+	}
+
 	/* No change MTime. */
 	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(NoMtimeCheck)))
 	{
@@ -1144,7 +1162,7 @@
 	/* Walk through the list, correlating, and updating the screen. */
 	struct GUIPhotoList* Walk;
 	struct GPSPoint* Result;
-	char* State;
+	char* State = "";
 	GtkTreePath* ShowPath;
 	for (Walk = FirstPhoto; Walk; Walk = Walk->Next)
 	{
--- a/main-command.c
+++ b/main-command.c
@@ -51,6 +51,7 @@
 	{ "verbose", no_argument, 0, 'v'},
 	{ "datum", required_argument, 0, 'd'},
 	{ "no-write", no_argument, 0, 'n'},
+	{ "force", no_argument, 0, 'F'},
 	{ "max-dist", required_argument, 0, 'm'},
 	{ "show", no_argument, 0, 's'},
 	{ "machine", no_argument, 0, 'o'},
@@ -83,6 +84,7 @@
 	printf("--verbose or -v: show what has been selected.\n");
 	printf("--datum or -d datum: specify measurement datum. If not set, WGS-84 used.\n");
 	printf("--no-write or -n: do not write the exif data. Useful with --verbose.\n");
+	printf("--force or -F: write exif data even if GPS tags already exist.\n");
 	printf("--max-dist or -m time: max time outside points that photo will be matched.\n");
 	printf("   Time is in seconds.\n");
 	printf("--show or -s: Just show the GPS data from the given files, if it exists.\n");
@@ -233,6 +235,7 @@
 	char* Datum = NULL;          /* Datum of input GPS data. */
 	int Interpolate = 1;         /* Do we interpolate? By default, yes. */
 	int NoWriteExif = 0;         /* Do we not write to file? By default, no. */
+	int OverwriteExisting = 0;
 	int ShowDetails = 0;         /* Do we show lots of details? By default, no. */
 	int FeatherTime = 0;         /* The "feather" time, in seconds. 0 = disabled. */
 	int ShowOnlyDetails = 0;
@@ -248,7 +251,7 @@
 	{
 		/* Call getopt to do all the hard work
 		 * for us... */
-		c = getopt_long(argc, argv, "g:z:ihvd:m:nsortMVfO:",
+		c = getopt_long(argc, argv, "g:z:ihvd:m:nsortFMVfO:",
 				program_options, 0);
 
 		if (c == -1) break;
@@ -303,6 +306,10 @@
 				/* This option specifies not to write to file. */
 				NoWriteExif = 1;
 				break;
+			case 'F':
+				/* This option specifies to overwrite existing GPS tags. */
+				OverwriteExisting = 1;
+				break;
 			case 'm':
 				/* This option gives us the allowable "feather" time. */
 				FeatherTime = atoi(optarg);
@@ -480,6 +487,7 @@
 	/* Set up our options structure for the correlation function. */
 	struct CorrelateOptions Options;
 	Options.NoWriteExif   = NoWriteExif;
+	Options.OverwriteExisting = OverwriteExisting;
 	Options.NoInterpolate = (Interpolate ? 0 : 1);
 	Options.TimeZoneHours = TimeZoneHours;
 	Options.TimeZoneMins  = TimeZoneMins;