UTM coordinates

Started by Bosun, March 06, 2016, 04:15:11 PM

Previous topic - Next topic

Bosun

I have exif data displaying GPS coodinates in ddmmss. Is ExifTool able to display coordinates in UTM format?

StarGeek

I don't believe that it can do so by default.

After doing a few google searches, am I correct in thinking that there are many ways in which to convert Lat and Long to UTM coordinates?  Just looking at the CPAN Geo::Coordinates::UTM page seems to indicate that there are at least 30 different variations.  It's probably possible to create user defined tags from the Geo::Coordinates::UTM code but then you would have to pick which ellipsoid to use.  Or create 90 different tags (3 for each ellipsoid)?


"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

StarGeek

#2
Edit: The attachment to this post is superseded by Phil's all in one version, which can be retrieved from the post below or from Sourceforge.




I noticed that in my images which I had used GeoSetter to set the gps locations, there was a tag named GPSMapDatum, which was set to one of the ellipsoid names on the Cpan page I linked above.  So with some trial and error, I was able to create a UTM location tags config file.  It does require some extra work, though.

First, in the directory where ExifTool is located, a few subdirectories need to be made.   They are lib/Math and lib/Geo/Coordinates.  Then, a few files need to be downloaded from CPAN.  In the lib/Math directory, download and save Trig.pm and Complex.pm.  Then, download and save UTM.pm to the lib/Geo/Coordinates directory.

After that, the attached ExifTool-GPS2UTM.config file can be downloaded.  It requires that the following tags are set in the target file:
GPS:GPSLatitudeRef, GPS:GPSLatitude, GPS:GPSLongitudeRef, GPS:GPSLongitude, and GPS:GPSMapDatum.  It can probably be made more flexible with regards to the tags, but I wasn't sure how things might work if only xmp gps tags were set.  Also, it would be possible to drop the GPS:GPSMapDatum and just hard code it to a specific ellipsoid if desired.  Or maybe just default to WGS-84 if it doesn't exist, since that appears to be the standard.

Once all those hurdles are met, the following tags become available through the config file: UTMEast, UTMNorth, and UTMZone.

It is important to realize that I have only done limited testing, only about five locations, all western US locations.  I compared the results to the responses I got on this website and the results from this config file were off by 1 at most, which was probably because the website seemed to be rounding up.

Example output:
c:\>exiftool -config ExifTool-GPS2UTM.config -UTM* -gps* -g1  Z:\Pictures\Camera_Pictures\Old_Town_San_Diego_State_Historic_Park_2015.08\2015-08-25_10.41.52.Nef -s
---- GPS ----
GPSVersionID                    : 2.2.0.0
GPSAltitudeRef                  : Below Sea Level
GPSTimeStamp                    : 17:41:52
GPSMapDatum                     : WGS-84
GPSDateStamp                    : 2015:08:25
---- Composite ----
GPSAltitude                     : 2.3 m Below Sea Level
GPSDateTime                     : 2015:08:25 17:41:52Z
GPSLatitude                     : 32 deg 45' 7.04" N
GPSLatitudeRef                  : North
GPSLongitude                    : 117 deg 11' 37.99" W
GPSLongitudeRef                 : West
GPSPosition                     : 32 deg 45' 7.04" N, 117 deg 11' 37.99" W
UTMEast                         : 481837.353846293
UTMNorth                        : 3623805.84354139
UTMZone                         : 11S
"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

Hi StarGeek,

This is excellent.  I had a bit of fun tampering with your code, and attached is a modified version with no dependencies on external libraries.

I have also generalized it a bit to use allow other GPS coordinates as input (as you alluded to, so it will now work for XMP and QuickTime coordinates as well as EXIF), although the drawback is that it will give incorrect results for EXIF GPS if the reference directions don't exist (which shouldn't happen, but it does seem to occasionally).  I don't know if you'll agree with all of my changes, but once we come to a consensus then maybe this is something that could be included in the ExifTool distribution.

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

StarGeek

Quote from: Phil Harvey on March 09, 2016, 09:27:32 AM
I don't know if you'll agree with all of my changes, but once we come to a consensus then maybe this is something that could be included in the ExifTool distribution.

Whatever you've done is fine by me.  My "code" was of 4 or 5 lines and it just done as an exercise, since I'll probably never use these tags.  All the work I did on it was just trying to gain access to to the cpan UTM module.  I'm just happy I figured that out, because there has been a few times when the use of one of them would have been useful.  And I'll also be looking at how you integrated them, because that was a problem for my limited knowledge.
"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

Milo

Where does the ExifTool-GPS2UTM-v2.config go on the system?  I'm using Ubuntu and have created the /usr/bin/lib/Math and /usr/bin/lib/Geo/Coordinates where ExifTool resides /usr/bin/exiftool I have added the three files referecened in StarGeek's post on March 08, 2016, 05:54:27 PM to the created directories. 

Alternatively, is it possible to add the tags UTMEast, UTMNorth and UTMZone to the exif metadata directly?  I have all the UTM Coordinates in the same file with all the other needed metadata and don't need a script to convert them during the initial GPS metadata import.

Phil Harvey

Quote from: Milo on December 20, 2016, 10:42:32 AM
Where does the ExifTool-GPS2UTM-v2.config go on the system?

See the comments in the sample config file for where ExifTool searches to find the config file. 

QuoteAlternatively, is it possible to add the tags UTMEast, UTMNorth and UTMZone to the exif metadata directly?

Yes, but you would have to create user-defined tags, probably in XMP, to store this information.

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

StarGeek

Quote from: Milo on December 20, 2016, 10:42:32 AM
I'm using Ubuntu and have created the /usr/bin/lib/Math and /usr/bin/lib/Geo/Coordinates where ExifTool resides /usr/bin/exiftool I have added the three files referecened in StarGeek's post on March 08, 2016, 05:54:27 PM to the created directories.

Ignore my post and use the config file created by Phil.  It negates the need for downloading the extra files.

Edit: Added note to my original post.
"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

mikelee33

Phil & StarGeek -

Really great work on your parts to come up with this very powerful option. 

I would indeed like to save these new UTM tags (or just a Composite:UTMCoordinates tag) to the file, but readily admit that I struggle as to how to proceed.  Config file syntax is my greatest weakness with ExifTool (no matter how many times I review the excellently written example.config file).

I am thinking that I could create the new tag/tags right in (and at the bottom of) the gps2utm.config file, or would that not be possible?  Would I have to actually write the three required tags in order to generate and write the composite tag?  If no, what would be the most straightforward way to write the composite UTMCoordinates tag?  I have this so far...

# Create and write composite tag
%Image::ExifTool::UserDefined = (
   'Image::ExifTool::Composite' => {   
        UTMCoordinates => {
      Require => {
      0 => 'UTMZone',
      1 => 'UTMEasting',
      2 => 'UTMNorthing',
# Not sure of following syntax, or how to specify multiple values
      ValueConv => '$val[0],$val[1],$val[2]',
                PrintConv => ???,
},
);

As you can see, I'm struggling.

Many thanks,
Mike
Mike

Phil Harvey

Hi Mike,

The Composite UTMCoordinates tag is already defined in the config file I posted.  If you want to create a user-defined tag to store this, then it should probably be in XMP, something like this:

%Image::ExifTool::UserDefined::utm = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-utm', 2 => 'Location' },
    NAMESPACE => { 'utm' => 'http://ns.myname.com/utm/1.0/' },
    WRITABLE => 'string', # (default to string-type tags)
    UTMCoordinates => { },
);

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::XMP::Main' => {
        utm => {
            SubDirectory => { TagTable => 'Image::ExifTool::UserDefined::utm' },
        },
    },
   # (the other user-defined Composite UTM tags go here)
);


Then the command would be:

exiftool -config my.config "-xmp:utmcoordinates<composite:utmcoordinates" FILE

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

mikelee33

Phil -

Thanks for you help.  This is where I'm still learning.  I could see the Composite UTMCoordinates tag defined in the config file, but reasoned (incorrectly) that I would need to redefine it to actually write it to file.  Creating and viewing a tag that isn't actually written to a file is a rather foreign concept to me.  I added your code to define the XMP tag to gps2utm.config (see attachment) and then ran the command:

exiftool -config gps2utm.config "-xmp:utmcoordinates<composite:utmcoordinates" IMG_0437.JPG

I get "Warning: No writable tags set from IMG_0437.JPG"

Am I getting close?  Have I defined the XMP tag incorrectly in the config file?

Mike

P.S. IMG_0437.JPG contains all the required GPS tags
Mike

Phil Harvey

Hi Mike,

The problem is that the new UserDefined definition is overriding the one that defines the Composite tags.  This is a common mistake, and is the reason I put the comment in my example.

You need to combine the Image::ExifTool::Composite and Image::ExifTool::XMP::Main definitions into a single Image::ExifTool::UserDefined lookup.  (Move the UTM tags down to the place I commented in my example, then delete their now-empty UserDefined lookup.)

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

mikelee33

Phil -

Got it!  You are correct, I didn't understand your comment to move the other (already defined) tags.  Everything works great now, and if I do say so, you've made your gps2utm.config file even more useful, in that it now writes the UTM coordinates which were requested.  Maybe you could add this to the config file (commented), then the user could wish to uncomment it if he wishes to write the data.  Just an idea.

Thank you very much for walking me through this.

Mike

P.S.  see write example (attached)
Mike

dericson

Quote from: Phil Harvey on March 09, 2016, 09:27:32 AMHi StarGeek,

This is excellent.  I had a bit of fun tampering with your code, and attached is a modified version with no dependencies on external libraries.

I have also generalized it a bit to use allow other GPS coordinates as input (as you alluded to, so it will now work for XMP and QuickTime coordinates as well as EXIF), although the drawback is that it will give incorrect results for EXIF GPS if the reference directions don't exist (which shouldn't happen, but it does seem to occasionally).  I don't know if you'll agree with all of my changes, but once we come to a consensus then maybe this is something that could be included in the ExifTool distribution.

- Phil

Hi Phil - Was this functionality ever incorporated into the tool?

Thanks!

StarGeek

Quote from: dericson on June 11, 2025, 04:36:15 PMHi Phil - Was this functionality ever incorporated into the tool?

No. You have to use the ExifTool-GPS2UTM-v2.config file that is attached to the post you quoted.

It's unlikely something to be included in the main program because there isn't demand for it. It's been 8 years since the original post without any questions about it.
"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