ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Bosun on March 06, 2016, 04:15:11 PM

Title: UTM coordinates
Post by: Bosun on March 06, 2016, 04:15:11 PM
I have exif data displaying GPS coodinates in ddmmss. Is ExifTool able to display coordinates in UTM format?
Title: Re: UTM coordinates
Post by: StarGeek on March 06, 2016, 05:35:21 PM
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 (http://search.cpan.org/~grahamc/Geo-Coordinates-UTM/UTM.pm) 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)?


Title: Re: UTM coordinates
Post by: StarGeek on March 08, 2016, 05:54:27 PM
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 (https://sourceforge.net/p/exiftool/code/ci/master/tree/config_files/gps2utm.config).




I noticed that in my images which I had used GeoSetter (http://www.geosetter.de/en/) 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 (http://cpansearch.perl.org/src/ZEFRAM/Math-Complex-1.59/lib/Math/Trig.pm) and Complex.pm (http://cpansearch.perl.org/src/ZEFRAM/Math-Complex-1.59/lib/Math/Complex.pm).  Then, download and save UTM.pm (http://cpansearch.perl.org/src/GRAHAMC/Geo-Coordinates-UTM-0.11/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 (http://leware.net/geo/utmgoogle.htm) 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
Title: Re: UTM coordinates
Post by: Phil Harvey on March 09, 2016, 09:27:32 AM
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
Title: Re: UTM coordinates
Post by: StarGeek on March 09, 2016, 05:26:51 PM
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.
Title: Re: UTM coordinates
Post by: Milo on December 20, 2016, 10:42:32 AM
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.
Title: Re: UTM coordinates
Post by: Phil Harvey on December 20, 2016, 11:38:15 AM
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 (https://exiftool.org/config.html) 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
Title: Re: UTM coordinates
Post by: StarGeek on December 20, 2016, 06:55:31 PM
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.
Title: Re: UTM coordinates
Post by: mikelee33 on July 20, 2017, 11:17:45 AM
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
Title: Re: UTM coordinates
Post by: Phil Harvey on July 20, 2017, 11:48:51 AM
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
Title: Re: UTM coordinates
Post by: mikelee33 on July 20, 2017, 12:58:33 PM
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
Title: Re: UTM coordinates
Post by: Phil Harvey on July 20, 2017, 01:20:23 PM
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
Title: Re: UTM coordinates
Post by: mikelee33 on July 20, 2017, 02:07:20 PM
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)
Title: Re: UTM coordinates
Post by: dericson on June 11, 2025, 04:36:15 PM
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!
Title: Re: UTM coordinates
Post by: StarGeek on June 11, 2025, 04:41:19 PM
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.
Title: Re: UTM coordinates
Post by: Phil Harvey on June 11, 2025, 04:50:23 PM
This config file is included in the full distribution.  Here is the current version (https://raw.githubusercontent.com/exiftool/exiftool/refs/heads/master/config_files/gps2utm.config) (no changes since 2016/03/09).

- Phil
Title: Re: UTM coordinates
Post by: dericson on June 11, 2025, 05:22:48 PM
Quote from: Phil Harvey on June 11, 2025, 04:50:23 PMThis config file is included in the full distribution.  Here is the current version (https://raw.githubusercontent.com/exiftool/exiftool/refs/heads/master/config_files/gps2utm.config) (no changes since 2016/03/09).

- Phil

Do I need to use a utm flag or anything?  I followed the directions as you described, but I am not seeing UTM tags in the response

Yep I was missing "-utm*"
Title: Re: UTM coordinates
Post by: StarGeek on June 11, 2025, 05:28:10 PM
What is the exact command you used and the exact output?

Here's an example of what I get using the config
C:\>exiftool -config gps2utm.config -G1 -a -s -c "%.6f" -GPS* -UTM* y:\!temp\Test4.jpg
[GPS]           GPSVersionID                    : 2.3.0.0
[GPS]           GPSLatitudeRef                  : North
[GPS]           GPSLatitude                     : 40.689200
[GPS]           GPSLongitudeRef                 : West
[GPS]           GPSLongitude                    : 74.044500
[Composite]     GPSLatitude                     : 40.689200 N
[Composite]     GPSLongitude                    : 74.044500 W
[Composite]     GPSPosition                     : 40.689200 N, 74.044500 W
[Composite]     UTMCoordinates                  : 18T 580735.871m E 4504695.165m N
[Composite]     UTMEasting                      : 580735.870703451
[Composite]     UTMNorthing                     : 4504695.16533812
[Composite]     UTMZone                         : 18T
Title: Re: UTM coordinates
Post by: Phil Harvey on June 11, 2025, 05:31:14 PM
You shouldn't have to specify "-utm*" (unless you have specified other tags to extracted).  When extracting all tags, the UTM tags should be generated as long as the config file is used an the GPS coordinates exist.

- Phil
Title: Re: UTM coordinates
Post by: StarGeek on June 11, 2025, 05:51:28 PM
Quote from: Phil Harvey on June 11, 2025, 05:31:14 PMYou shouldn't have to specify "-utm*" (unless you have specified other tags to extracted).  When extracting all tags, the UTM tags should be generated as long as the config file is used an the GPS coordinates exist.

I only wanted to show the GPS and UTM tags to show that the config file worked. All other tags where unnecessary for the example.
Title: Re: UTM coordinates
Post by: Phil Harvey on June 11, 2025, 07:25:45 PM
@StarGeek:  Understood.  My comment was in response to dericson's last post, and was actually composed before I saw yours.

- Phil
Title: Re: UTM coordinates
Post by: StarGeek on June 11, 2025, 08:13:05 PM
Quote from: Phil Harvey on June 11, 2025, 07:25:45 PMand was actually composed before I saw yours.

As is tradition...
:D
Title: Re: UTM coordinates
Post by: Phil Harvey on June 11, 2025, 08:20:04 PM
:P
Title: Re: UTM coordinates
Post by: dericson on June 12, 2025, 06:46:59 AM
I got it up and running.  In the end all I had to do was restart my terminal.  Thanks!!