ExifTool Forum

ExifTool => Newbies => Topic started by: dvertz on February 10, 2019, 01:42:10 PM

Title: Need help with Filesequence and IF
Post by: dvertz on February 10, 2019, 01:42:10 PM
OK. After two days of researching and reading everything, I can't seem to find the answer.

I have this command working with 2 exceptions.

Code: [Select]
exiftool -n -f -p $FileSequence,$Composite:gpslatitude,$Composite:gpslongitude,$Composite:gpsaltitude,$filename,$exif:GPSImgDirection,$Composite:FOV .\images > LATLON.csv
1. I have read someplace that $FileSequence can be started at 1 instead of 0 (zero), but it cannot be started at any other number. Perfect, because that's all I need, to start at 1. But I cannot find an example of how to do just that. I think it may have something to do with the formatting I have seen and don't understand. $FileSequence;$_=sprintf('%03d', $_+1
2. A little more tricky. I found that exiftool supports the "IF" statement. I am sure that is what I need to use, just not sure how. I would like to have the lines written only if Lat and Long exist. And if they exist and any other tag does not exist, then use the forceprint hyphen.

Thanks for any help you can give.
Title: Re: Need help with Filesequence and IF
Post by: StarGeek on February 10, 2019, 03:27:30 PM
1. I have read someplace that $FileSequence can be started at 1 instead of 0 (zero), but it cannot be started at any other number. Perfect, because that's all I need, to start at 1. But I cannot find an example of how to do just that. I think it may have something to do with the formatting I have seen and don't understand. $FileSequence;$_=sprintf('%03d', $_+1

That can be done with the Advanced formatting feature (https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#Advanced-formatting-feature).  It's basically inserting Perl commands into the tags.  To start FileSequence at a different number, all you need is ${FileSequence;$_+=#}, replacing the hashtag with whatever number you want to start with.    If you want to have leading zeroes (e.g. 001, 002, 003), then the ${FileSequence;$_=sprintf('%03d',$_+1} would be what you want, where 3 is the minimum number of digits to appear in the output and 1 is the starting number.

I would suggest putting quotes around all the tag names that you want included following the -p (printFormat) option (https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#p-FMTFILE-or-STR--printFormat).  One space, accidental or on purpose, would give you incomplete output.
Code: [Select]
-p "${FileSequence;$_=sprintf('%03d',$_+1},$Composite:gpslatitude,$Composite:gpslongitude,$Composite:gpsaltitude,$filename,$exif:GPSImgDirection,$Composite:FOV"
Quote
2. A little more tricky. I found that exiftool supports the "IF" statement. I am sure that is what I need to use, just not sure how. I would like to have the lines written only if Lat and Long exist. And if they exist and any other tag does not exist, then use the forceprint hyphen.

To show files that have latitude and longitude, then all you need to add is -if "$GPSLatitude and $GpsLongitude".  There isn't a way to say if GPSLatitude and GpsLongitude and nothing else, though.  You can either include the -f (ForcePrint) option (https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#f--forcePrint) or not.
Title: Re: Need help with Filesequence and IF
Post by: dvertz on February 11, 2019, 06:30:27 PM
StarGeek,
Thank you for such a fast reply.
Once I got it typed in correctly, the solution ${FileSequence;$_+=1} work perfectly.

However, I must be doing things wrong for the IF statement. I am guessing that it would work as any programming language I have known by using "If, then, else".

So I tucked -if "$GPSLatitude and $GpsLongitude" in front of the rest like this ...

Code: [Select]
exiftool -if "$GPSLatitude and $GpsLongitude" -n -f -p "${FileSequence;$_+=1},$Composite:gpslatitude,$Composite:gpslongitude,$Composite:gpsaltitude,$filename,$exif:GPSImgDirection,$Composite:FOV" .\images > LATLON.csv
My result was missing files that had good $Composite:gpslatitude and $Composite:gpslongitude
Noticing that $GPSLatitude is not the same as $Composite:gpslatitude I tried changing to ...

Code: [Select]
exiftool -if "$Composite:gpslatitude and $Composite:gpslongitude" -n -f -p "${FileSequence;$_+=1},$Composite:gpslatitude,$Composite:gpslongitude,$Composite:gpsaltitude,$filename,$exif:GPSImgDirection,$Composite:FOV" .\images > LATLON.csv
and got the same result of missing lines written. (71 of 86 files failed condition)
There are a total of 14 files out of 157 that should not be written in this test group.

When I remove the -if statement they all write data. One of the missing files is the very first one.
I see nothing wrong with this line for it to fail the condition.
1,36.703276,-76.3464419722222,-35.627,20190115_113017.jpg,-,69.3903656740024

But I need to stop this line from being written.
30,-,-,-,20190115_115352.jpg,-,69.3903656740024

I even tried to simplify it by running the -if on just $Composite:gpslatitude (because if one doesn't exist, then most likely the other wont either).
But that failed just the same way.

Yes, I found in my lengthy research that I needed the $Composite:gpslongitude instead of the $GpsLongitude because of the missing negative sign. I need that for the software this being imported into.

Oh. Does it matter that I am running this on Windows 8.1 without Perl?
Title: Re: Need help with Filesequence and IF
Post by: StarGeek on February 11, 2019, 08:48:57 PM
There shouldn't be a difference between GPSLatitude and Composite:GPSLatitude, as I'm pretty sure the plain tag is filled by the Composite tag by default.  There could be a difference if you used EXIF or GPS explicitly, though.

I copy/pasted your command, removing the part after the directory, and tested it here on two files.  One with GPS coordinates and one with out.  The output was as expected:

Code: [Select]
C:\>exiftool  -if "$GPSLatitude and $GpsLongitude" -n -f -p "${FileSequence;$_+=1},$Composite:gpslatitude,$Composite:gpslongitude,$Composite:gpsaltitude,$filename,$exif:GPSImgDirection,$Composite:FOV"  y:\!temp\Test4.jpg  y:\!temp\Test5.jpg
1,36.703276,-76.3464419722167,-,Test4.jpg,-,36.2437511095896
    1 files failed condition

What is the output of
exiftool -g1 -a -s -GPS*
on a file with and without gps coordinates?

To trouble shoot, go back to the basic command
exiftool -if "$GPSLatitude and $GpsLongitude" -GPSLatitude  -GPSLongitude
and see if that works.
Title: Re: Need help with Filesequence and IF
Post by: dvertz on February 13, 2019, 07:57:56 PM
StarGeek
Sorry to take so long getting back. I was wrapped up in the second half of this procedure. Once I get the data I am bring it into another place using another program.

Wow. This became very interesting very fast.

I first ran the basic command to see what would happen. I got the exact same missing files as the full command. So I went to check the JPG files to see what could be wrong with the files themselves. That's when I discovered I was missing some files in both methods (with or without the IF function).

So then I ran the other command you gave. That provided the data on all files including the files that were missing but was with the "36 deg 42' 11.79" N" format which I can't use in my other program. So I added the -n to the line and wrote it out again. It still read the missing files and presented the information.

Here is the output from
exiftool -g1 -a -n -s -GPS*  .\images > all.csv
image ending in 3017.jpg is always missed (not correct).
image ending in 3019.jpg is only missed when using IF (not correct).
image ending in 3309.jpg is always exported (correct).
image ending in 3322.jpg is exported only when IF is not used (correct).

I really just cant see the problem.
I wonder if it has anything to do with the coordinates being exactly the same for all three files, as the person did not move (they only turned) when taking all three images.

======== ./images/20190115_113017.jpg
---- GPS ----
GPSLatitudeRef                  : N
GPSLatitude                     : 36.703276
GPSLongitudeRef                 : W
GPSLongitude                    : 76.3464419722222
GPSAltitudeRef                  : 1
GPSAltitude                     : 35.627
GPSTimeStamp                    : 16:30:12
GPSProcessingMethod             : GPS
GPSDateStamp                    : 2019:01:15
---- Composite ----
GPSAltitude                     : -35.627
GPSDateTime                     : 2019:01:15 16:30:12Z
GPSLatitude                     : 36.703276
GPSLongitude                    : -76.3464419722222
GPSPosition                     : 36.703276 -76.3464419722222
======== ./images/20190115_113019.jpg
---- GPS ----
GPSLatitudeRef                  : N
GPSLatitude                     : 36.703276
GPSLongitudeRef                 : W
GPSLongitude                    : 76.3464419722222
GPSAltitudeRef                  : 1
GPSAltitude                     : 35.627
GPSTimeStamp                    : 16:30:12
GPSProcessingMethod             : GPS
GPSDateStamp                    : 2019:01:15
---- Composite ----
GPSAltitude                     : -35.627
GPSDateTime                     : 2019:01:15 16:30:12Z
GPSLatitude                     : 36.703276
GPSLongitude                    : -76.3464419722222
GPSPosition                     : 36.703276 -76.3464419722222
======== ./images/20190115_113309.jpg
---- GPS ----
GPSLatitudeRef                  : N
GPSLatitude                     : 36.703276
GPSLongitudeRef                 : W
GPSLongitude                    : 76.3464419722222
GPSAltitudeRef                  : 1
GPSAltitude                     : 35.627
GPSTimeStamp                    : 16:30:12
GPSProcessingMethod             : GPS
GPSDateStamp                    : 2019:01:15
---- Composite ----
GPSAltitude                     : -35.627
GPSDateTime                     : 2019:01:15 16:30:12Z
GPSLatitude                     : 36.703276
GPSLongitude                    : -76.3464419722222
GPSPosition                     : 36.703276 -76.3464419722222
======== ./images/20190115_113322.jpg
======== ./images/20190115_113659.jpg


Thanks for your help on this.
Title: Re: Need help with Filesequence and IF
Post by: StarGeek on February 14, 2019, 12:24:55 PM
I have to say I'm stumped.  That basic command should work for any file that has a GPSLatitude/GPSLongitude tag (that isn't 0/0 or otherwise exists but is empty) regardless of the location group (GPS, XMP).  The last option I can offer would be
-if "defined $GPSLatitude"

That provided the data on all files including the files that were missing but was with the "36 deg 42' 11.79" N" format which I can't use in my other program. So I added the -n to the line and wrote it out again.

Just in case you run into a situation where the -n (printConv) option (https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#n---printConv) interferes with the output of some other tag, for example, Orientation, you can use a trailing hashtag to force the -n result on a single tag, e.g. -GPSLatitude#, or if you're dumping all data, use the -c (coordFormat) option (https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#c-FMT--coordFormat) to change the GPS format.

Quote
I wonder if it has anything to do with the coordinates being exactly the same for all three files, as the person did not move (they only turned) when taking all three images.

No, because exiftool processes files one at a time.  Unless you write a config file to do otherwise, the output of one file won't affect the output of another.