Main Menu

Conditional operation

Started by Happy Hobo, August 14, 2023, 03:39:00 PM

Previous topic - Next topic

Happy Hobo

Assumption:
  • I know the time zone of a set of images and videos.
  • Some files (the videos) have no DateTimeOriginal and have UTC in CreateDate
  • GPSDateTime is correct in all files

How would I do ...
if CreateDate = GPSDateTime,
  correct CreateDate to be local time (in that zone)then only if latitude and longitude are not present
  exiftool -v2 -geotag $GPX '-Geotime<${CreateDate#}ZONE' $DIR (or $DIR/*)WITHOUT re-writing GPSDateTime

(ZONE=time zone offset with sign, e.g., +02:00:00 for Spain)

I'm doing all files in a directory, but I can do one at a time in a loop if the conditional requires that.  And if the coordinates are wrong, I don't want to change them.

Phil Harvey

1. How do you know the time zone of the images?  This would be easy if it was, say, in a tag called "TimeZone" (see command below).

2. Geotagging without writing GPS date/time isn't possible, but you can copy the gps date/time back into itself in the same command to preserve the original values.

So your command could look like this:

exiftool -v2 -geotag $GPX '-geotime<${createdate#}$timezone' -gpstimestamp -gpsdatestamp $DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Happy Hobo

Quote from: Phil Harvey on August 14, 2023, 09:07:03 PM1. How do you know the time zone of the images?  This would be easy if it was, say, in a tag called "TimeZone" (see command below).
I know the time zone because I took the pictures and also because the lat/long in the GPX file tells me where it happened.
Quote from: Phil Harvey on August 14, 2023, 09:07:03 PMexiftool -v2 -geotag $GPX '-geotime<${createdate#}$timezone' -gpstimestamp -gpsdatestamp $DIR
If the image already has lat/long, is that going to re-write them?

Phil Harvey

Yes, but add this to avoid writing files which already contain GPSLatitude:

-if "not $gpslatitude"

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Happy Hobo

Quote from: Phil Harvey on August 14, 2023, 09:07:03 PM2. Geotagging without writing GPS date/time isn't possible, but you can copy the gps date/time back into itself in the same command to preserve the original values.
If GPSDateTime is correct and I use "-Geotime<GPSDateTime#" ... I assume GPSDateTime will end up with the same value?  Doesn't matter whether it is rewritten or not as long as the value ends up the same.  I need to write any missing GPSDateTime from DataTimeOriginal prior to this anyway.

Happy Hobo

I went ahead and tried
exiftool -v2 -geotag <file> '-geotime<${datetimeoriginal#}01:00' -gpstimestamp -gpsdatestamp *jpg *PNG *JPG
It said nine files were changed.  When I checked, nine files had the same lat/long they had before, and other files that were in the time range of the GPX file had the same GPSDateTime and DatTimeOriginal as before but still no lat/long.

Happy Hobo

Then I tried this one:
exiftool -v2 if 'not $gpslatitude' -geotag <file> '-geotime<${datetimeoriginal#}-01:00' -gpstimestamp -gpsdatestamp *jpg *PNG *JPG
Files that had a DateTimeOPriginal but no GPSDateTime were not tagged.  And files that had both were not tagged if the GPSDateTime format was different:geotag.jpg

StarGeek

Quote from: Happy Hobo on September 04, 2023, 01:18:46 PMI went ahead and tried
exiftool -v2 -geotag <file> '-geotime<${datetimeoriginal#}01:00' -gpstimestamp -gpsdatestamp *jpg *PNG *JPG

In this case I believe you are missing the (±) in front of the time zone
exiftool -v2 -geotag <file> '-geotime<${datetimeoriginal#}+01:00' -gpstimestamp -gpsdatestamp *jpg *PNG *JPG

Most time zone related tags include the ± as part of the data, so when using a tag such as Timezone (a MakerNotes tag, I believe) or one of the OffsetTime* tags, you wouldn't need to include it.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Quote from: Happy Hobo on September 04, 2023, 02:25:34 PMFiles that had a DateTimeOPriginal but no GPSDateTime were not tagged.  And files that had both were not tagged if the GPSDateTime format was different

Can you provide some sample files and the geotrack you're using?  Because I'm not quite clear on what's happening.

One thing that I will point out is that the only time GPSDateTime is going to show a time zone is when the only tag in the file is XMP-exif:GPSDateTime, which your command doesn't deal with.

Example output, notice in Test3.jpg, there exists the GPS/EXIF date and time stamp tags as well as the XMP:GPSDateTime.  Composite tags always have priority because they are created last and without the -a (-duplicates) option, they will be the tags listed. And the Composite:GPSDateTime is created by combining the GPSDateStamp and GPSTimeStamp tags and doesn't read the XMP:GPSDateTime tag.

But in Test4.jpg, the XMP:GPSDateTime is the only tag that exists, so that is what is displayed for GPSDateTime.  And that is the only time GPSDateTime will display a time zone other than Z
======== y:/!temp/Test3.jpg
[GPS]          GPSVersionID                    : 2.3.0.0
[GPS]          GPSTimeStamp                    : 12:00:00
[GPS]          GPSDateStamp                    : 2023:09:04
[XMP-exif]     GPSDateTime                     : 2023:09:04 11:00:00-01:00
[Composite]    GPSDateTime                     : 2023:09:04 12:00:00Z
======== y:/!temp/Test4.jpg
[XMP-exif]      GPSDateTime                    : 2023:09:04 11:00:00-01:00
    2 image files read

Moral of the story, always use the command in FAQ #3 to see all the data and their locations ;)
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Happy Hobo

Quote from: StarGeek on September 04, 2023, 04:48:07 PMIn this case I believe you are missing the (±) in front of the time zone
exiftool -v2 -geotag <file> '-geotime<${datetimeoriginal#}+01:00' -gpstimestamp -gpsdatestamp *jpg *PNG *JPG
I thought I had included it, but when I put it in, it seems to have worked.  Unfortunately, I forgot to include the conditional, so it changed the ones that already had geotags.  Those were tastes from the phone camera and the GPX file was from a Garmin device.  But the difference was typically much less than a meter, so not very important.

One thing that takes getting used to is that the zone is the difference from UTC, not the correction.  So I have to say "+01:00" to make it subtract an hour.

Happy Hobo

I repeated with the minus sign included and it worked.  But then I had another directory with different time zones but GPSDateTime already correct, and the following did not work:
WGroleau@MBP 14日 % exiftool *PNG | grep GPS                                       
GPS Date/Time                   : 2018:03:14 10:50:26Z
GPS Date/Time                   : 2018:03:14 14:45:30Z
WGroleau@MBP 14日 % exiftool -v2  -geotag 'temp-u.gpx'  "-geotime<${gpsdatetime#}" -gpstimestamp -gpsdatestamp *PNG
Loaded 11 points from XML-format GPS track log file 'temp-u.gpx'
  GPS track start: 2018:03:14 03:25:55.000 UTC
  GPS track end:   2018:03:14 22:12:02.000 UTC
Writing File:Geotag
======== 20180314_025026.PNG
Setting new values from 20180314_025026.PNG
Warning: No writable tags set from 20180314_025026.PNG
Nothing changed in 20180314_025026.PNG
======== 20180314_094530.PNG
Setting new values from 20180314_094530.PNG
Warning: No writable tags set from 20180314_094530.PNG
Nothing changed in 20180314_094530.PNG
    0 image files updated
    2 image files unchanged

StarGeek

#11
Run your first command as (gives all the data and skips needing to grep)
exiftool -G1 -a -s '-GPS*' *PNG

Then run your geotag command with -v3 instead of -v2.  That will show the time that exiftool is reading from the file.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Happy Hobo

I've already (somehow) fixed that directory, but no doubt another will be found to try that on.