Permalink
Browse files

Erase any GPS tags before adding new ones

This prevents duplicate GPS tags in the final file, which could
happen if the same tags already existed in the original file.
Correlation would normally abort with a "GPS Already Present"
error were a file already geotagged, but since only the presence
of the GPSLatitude tag is checked, others might still exist
undetected.
  • Loading branch information...
1 parent 1fe0040 commit 22d276a27012ad86c36a77b8f4e9376136bd5348 @dfandrich dfandrich committed Dec 25, 2012
Showing with 24 additions and 11 deletions.
  1. +2 −0 RELEASES
  2. +22 −11 exif-gps.cpp
View
@@ -143,3 +143,5 @@ v1.6.2git: TBD
- --machine output is no longer dependent on the current locale
- Fixed time calculations spanning DST discontinuities
- Only write an altitude tag if it exists in the GPX file
+ - Prevent duplicate GPS tags in the final file (which could
+ happen if some tags already existed before correlation)
View
@@ -372,6 +372,21 @@ char* ReadGPSTimestamp(const char* File, char* DateStamp, char* TimeStamp, int*
return Copy;
}
+static void EraseGpsTags(Exiv2::ExifData &ExifInfo)
+{
+ // Search through, find the keys that we want, and wipe them
+ // Code below submitted by Marc Horowitz
+ Exiv2::ExifData::iterator Iter;
+ for (Exiv2::ExifData::iterator Iter = ExifInfo.begin();
+ Iter != ExifInfo.end(); )
+ {
+ if (Iter->key().find("Exif.GPSInfo") == 0)
+ Iter = ExifInfo.erase(Iter);
+ else
+ Iter++;
+ }
+}
+
static void ConvertToRational(double Number, int Decimals, char *Buf, int BufSize)
{
// This function converts the given decimal number
@@ -497,6 +512,12 @@ int WriteGPSData(const char* File, const struct GPSPoint* Point,
Exiv2::ExifData &ExifToWrite = Image->exifData();
+ // Make sure we're starting from a clean GPS IFD.
+ // There might be lots of GPS tags existing here, since only the
+ // presence of the GPSLatitude tag causes correlation to stop with
+ // "GPS Already Present" error.
+ EraseGpsTags(ExifToWrite);
+
char ScratchBuf[100];
// Do all the easy constant ones first.
@@ -739,17 +760,7 @@ int RemoveGPSExif(const char* File, int NoChangeMtime)
return 0;
}
- // Search through, find the keys that we want, and wipe them
- // Code below submitted by Marc Horowitz
- Exiv2::ExifData::iterator Iter;
- for (Exiv2::ExifData::iterator Iter = ExifInfo.begin();
- Iter != ExifInfo.end(); )
- {
- if (Iter->key().find("Exif.GPSInfo") == 0)
- Iter = ExifInfo.erase(Iter);
- else
- Iter++;
- }
+ EraseGpsTags(ExifInfo);
try {
Image->writeMetadata();

0 comments on commit 22d276a

Please sign in to comment.