Tags: patch

I finally got around to doing this myself - please consider adding or
upstreaming this patch:

diff -r -u gpscorrelate-1.6.1/correlate.c gpscorrelate-1.6.1+tms.1/correlate.c
--- gpscorrelate-1.6.1/correlate.c	2007-06-21 15:31:49.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/correlate.c	2013-04-26 09:45:25.464853539 +0100
@@ -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... */
diff -r -u gpscorrelate-1.6.1/correlate.h gpscorrelate-1.6.1+tms.1/correlate.h
--- gpscorrelate-1.6.1/correlate.h	2007-06-21 15:31:49.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/correlate.h	2013-04-26 09:44:12.656247487 +0100
@@ -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. */
diff -r -u gpscorrelate-1.6.1/debian/changelog gpscorrelate-1.6.1+tms.1/debian/changelog
--- gpscorrelate-1.6.1/debian/changelog	2012-05-06 23:28:10.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/debian/changelog	2013-04-26 10:30:33.559152896 +0100
@@ -1,3 +1,9 @@
+gpscorrelate (1.6.1-4+tms.1) unstable; urgency=low
+
+  * Add ability to force overwriting of existing tags
+
+ -- Toby Speight <t.m.speight...@cantab.net>  Fri, 26 Apr 2013 09:31:14 +0100
+
 gpscorrelate (1.6.1-4) unstable; urgency=low
 
   * Update Maintainer field with Debian email.
diff -r -u gpscorrelate-1.6.1/doc/command.html gpscorrelate-1.6.1+tms.1/doc/command.html
--- gpscorrelate-1.6.1/doc/command.html	2007-06-21 15:31:49.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/doc/command.html	2013-04-26 10:14:59.547518455 +0100
@@ -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.
diff -r -u gpscorrelate-1.6.1/doc/gpscorrelate-manpage.xml.in gpscorrelate-1.6.1+tms.1/doc/gpscorrelate-manpage.xml.in
--- gpscorrelate-1.6.1/doc/gpscorrelate-manpage.xml.in	2008-10-31 11:50:39.000000000 +0000
+++ gpscorrelate-1.6.1+tms.1/doc/gpscorrelate-manpage.xml.in	2013-04-26 09:56:46.094513109 +0100
@@ -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>,
diff -r -u gpscorrelate-1.6.1/doc/gui.html gpscorrelate-1.6.1+tms.1/doc/gui.html
--- gpscorrelate-1.6.1/doc/gui.html	2007-06-21 15:31:49.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/doc/gui.html	2013-04-26 10:13:34.086815903 +0100
@@ -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>
diff -r -u gpscorrelate-1.6.1/exif-gps.cpp gpscorrelate-1.6.1+tms.1/exif-gps.cpp
--- gpscorrelate-1.6.1/exif-gps.cpp	2013-05-02 17:44:42.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/exif-gps.cpp	2013-04-26 11:02:11.142842258 +0100
@@ -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",
@@ -702,16 +711,14 @@
 			TimeStamp.tm_mon + 1,
 			TimeStamp.tm_mday);
 	Value->read(ScratchBuf);
-	ExifToWrite.erase(ExifToWrite.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSDateStamp")));
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSDateStamp"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSDateStamp"), Value.get());
 	
 	Value = Exiv2::Value::create(Exiv2::signedRational);
 	snprintf(ScratchBuf, 100, "%d/1 %d/1 %d/1",
 			TimeStamp.tm_hour, TimeStamp.tm_min,
 			TimeStamp.tm_sec);
 	Value->read(ScratchBuf);
-	ExifToWrite.erase(ExifToWrite.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSTimeStamp")));
-	ExifToWrite.add(Exiv2::ExifKey("Exif.GPSInfo.GPSTimeStamp"), Value.get());
+	replace(ExifToWrite, Exiv2::ExifKey("Exif.GPSInfo.GPSTimeStamp"), Value.get());
 	
 	Image->writeMetadata();
 	
diff -r -u gpscorrelate-1.6.1/gui.c gpscorrelate-1.6.1+tms.1/gui.c
--- gpscorrelate-1.6.1/gui.c	2013-05-02 17:44:42.000000000 +0100
+++ gpscorrelate-1.6.1+tms.1/gui.c	2013-04-26 10:45:13.034343756 +0100
@@ -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)
 	{
diff -r -u gpscorrelate-1.6.1/main-command.c gpscorrelate-1.6.1+tms.1/main-command.c
--- gpscorrelate-1.6.1/main-command.c	2010-02-13 03:18:09.000000000 +0000
+++ gpscorrelate-1.6.1+tms.1/main-command.c	2013-04-30 20:36:18.175471980 +0100
@@ -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;

Reply via email to