Lat/Long/Alt not retaining negative value

Started by michaelthebike, June 10, 2022, 06:13:08 AM

Previous topic - Next topic

michaelthebike

Hello

I appreciate there have been a number of posts on this matter such as https://exiftool.org/forum/index.php?topic=9639.0 and tapping the glass at FAQ #14, but alas the fixes do not work.

For example I have a simple csv file as below:
SourceFile,GPSLatitude,GPSLongitude,GPSAltitude
1.jpg,-1.835,52.5,-2.45


Because Windows only accepts Degrees/Minutes/Seconds, it is converted. However the negatives are not retained. The script I have been using is:
exiftool -csv=data.csv -GPSLatitudeRef=S -GPSLongitudeRef=W -gpsaltituderef=above .

Some recommendations had been to use the -n flag to retain the negatives. I have also tried various things - even at the detriment of data and common sense - to try and force a negative, such as -GPSLatitudeRef=N (dumb I know)

In short, despite reading the FAQ and despite trying everything I could throw at it, Windows refuses to take on the negative. Otherwise it appears the DMS format is OK. Can anyone suggest any amendments to my code?

While I am OK at coding in general, I suck at DMS and coordinates in general.

StarGeek

#1
It's only after typing all this up and posting that I realized what the actual problem was.  And the problem is Windows.  Windows doesn't display the reference directions and there isn't anything you can do about that.  Even setting with another program such as Adobe Bridge doesn't add the directions.

I'm going to leave all this up, though, so I can point to this post next time someone needs to know about the reference tags.



The EXIF GPS tags are split into two separate tags.  One tag holds the actual GPS coordinates and one tag to hold the reference direction, e.g. North/South/East/West/Above/Below.  You have to set both tags.

The coordinate tags are unsigned, meaning they cannot hold a negative value.  The associated reference tag is what decides if the coordinates are negative or positive.

The first row of your example csv files needs to have all of these entries, though order doesn't matter except for the SourceFile column, which must be first
SourceFile,GPSLatitudeRef,GPSLatitude,GPSLongitudeRef,GPSLongitude,GPSAltitudeRef,GPSAltitude

When writing, exiftool does not required the reference directions to be exactly North/South/East/West/Above/Below.  It can accept the raw numbers and will make the necessary conversions.  So it is usually easier to just duplicate the actual coordinate tags and add Ref to the end.  For example, if you're using a spreadsheet, you could do this


Quote from: michaelthebike on June 10, 2022, 06:13:08 AM
Because Windows only accepts Degrees/Minutes/Seconds, it is converted. However the negatives are not retained.

This is only how Windows will accept and display the data, but when using exiftool, it doesn't matter how you enter the data, as per FAQ #14.  This is because no matter how it is entered, by whatever program is used, it is stored in the file in only one way.  It is not stored as a set of three numbers (deg/min/sec) nor is it stored as a simple decimal number.  It's more complicated than that and I can go into the details if you really want, but it isn't necessary to know in order to write the data.

So, when writing, if you're using a csv file, then it needs to look like the spreadsheet above.  If you're writing on the command line, there are multiple ways to write the data.

If you want to be exacting using decimal numbers, you could use
exiftool -GPSLatitudeRef=S -GPSLatitude=1.835 -GPSLongitudeRef=E -GPSLongitude=52.5 -GPSAltitudeRef=Above -GPSAltitude=2.45 file.jpg

If you want to use deg/min/sec, your best off dropping the quotes for minutes and seconds, as it can cause problems on the command line.  It's easier to just use the three numbers as per FAQ #14 but you do need quotes around the all three numbers
exiftool -GPSLatitudeRef=South -GPSLatitude="1 50 6.00" -GPSLongitudeRef=East -GPSLongitude="52 30 0.00" -GPSAltitudeRef=Above -GPSAltitude=2.45 file.jpg

But in my opinion, the best way is to use exiftool's wildcard ability when writing.
exiftool -GPSLatitude*=-1.835 -GPSLongitude*=52.5 -GPSAltitude*=2.45 file.jpg
or
exiftool -GPSLatitude*="-1 50 6.00" -GPSLongitude*="52 30 0.00" -GPSAltitude*=2.45 file.jpg

Full example of commands:
C:\Programs\My_Stuff>exiftool -P -overwrite_original -GPSLatitude*=-1.835 -GPSLongitude*=52.5 -GPSAltitude*=2.45 y:\!temp\Test4.jpg
    1 image files updated

C:\Programs\My_Stuff>exiftool -G1 -a -s -e -gpsL* -gpsa* y:\!temp\Test4.jpg
[GPS]           GPSLatitudeRef                  : South
[GPS]           GPSLatitude                     : 0 deg 9' 54.00"
[GPS]           GPSLongitudeRef                 : East
[GPS]           GPSLongitude                    : 52 deg 30' 0.00"
[Composite]     GPSLatitude                     : 0 deg 9' 54.00" S
[Composite]     GPSLongitude                    : 52 deg 30' 0.00" E
[GPS]           GPSAltitudeRef                  : Above Sea Level
[GPS]           GPSAltitude                     : 2.45 m
[Composite]     GPSAltitude                     : 2.4 m Above Sea Level

C:\Programs\My_Stuff>exiftool -P -overwrite_original -all= y:\!temp\Test4.jpg
    1 image files updated

C:\Programs\My_Stuff>exiftool -P -overwrite_original -GPSLatitude*="-1 50 6.00" -GPSLongitude*="52 30 0.00" -GPSAltitude*=2.45 y:\!temp\Test4.jpg
    1 image files updated

C:\Programs\My_Stuff>exiftool -G1 -a -s -gpsL* -gpsa* y:\!temp\Test4.jpg
[GPS]           GPSLatitudeRef                  : South
[GPS]           GPSLatitude                     : 0 deg 9' 54.00"
[GPS]           GPSLongitudeRef                 : East
[GPS]           GPSLongitude                    : 52 deg 30' 0.00"
[Composite]     GPSLatitude                     : 0 deg 9' 54.00" S
[Composite]     GPSLongitude                    : 52 deg 30' 0.00" E
[GPS]           GPSAltitudeRef                  : Above Sea Level
[GPS]           GPSAltitude                     : 2.45 m
[Composite]     GPSAltitude                     : 2.4 m Above Sea Level


Result in Windows properties

And as you pointed out, Windows doesn't display the references direction.  There really isn't anything you can do about this, as it's a Windows problem.  Even setting with another program such as Adobe Bridge, the results are the same.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

...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 ($).

StarGeek

Quote from: Phil Harvey on June 10, 2022, 11:04:44 AM
Wow.  Great explanation!

And somehow I missed what the actual problem was until I posted it all and actually looked at the Windows properties image I had posted.  Still, it'll be a good reference to point to.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

michaelthebike

Stargeek (and Phil while I'm at it) thanks as ever for the bountiful information and hopefully my description or lack of did not throw you off too much.

StarGeek

Quote from: michaelthebike on June 13, 2022, 09:30:37 AMhopefully my description or lack of did not throw you off too much.

No, it was fine.  I was just jumping to conclusions about what the actual question was.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype