Performing Math on Latitude and Longiude

Started by flightfollowing, October 28, 2012, 02:47:49 PM

Previous topic - Next topic

flightfollowing

I am trying to use exiftool and the exiftool config file to create individual xml sidecar like files for every image. The xml file needs to have an adjusted latitude and longitude from what is already written in the exif file, so I need to perform some math on the lat and long, and I am not having success in achieving this.

Here is a piece of the config file, and the template file, as well as the command to run it:


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        GPSNorthCover => {
            Require => 'GPSlatitude',
            ValueConv => '$val + .1',
        },
PitchTest => {
            Require => 'GPSPitch',
            ValueConv => '$val - .1',
        },

TEMPLATE:

<imageType> $Copyright </imageType>
<pointLocation> $GPSlongitude $GPSlatitude </pointLocation>
<resolution>10</resolution>
<dateYear> 2012 </dateYear>
<dateDay> 8 </dateDay>
<dateMonth> 5 </dateMonth>
<coverage> $GPSNorthCover $GPSEastCover  </coverage>

COMMAND:

#exiftool -n -w! xml -p template.txt *.cr2


The calculation on the pitch works fine, but the one on GPS latitude does not, and I suspect that the storage of the GPS data as 3 individual fields prevents proper conversion.  Using the -n tag on the command line works great, but I do not know how to achieve the equivalent in the config file? I am hoping to use decimal degrees to to perform the math on the new user defined coordinates.

Also, I am trying to extract individual month, day, and year values for the xml sidecar files, but also not sure how to format the template file to make this happen, as you can see above I just hardcoded the month day and year digits, but would like to extract them from the exif data as well.

Any advice would be greatly appreciated.

Phil Harvey

What you have done should work, but the tag names in the config file are case sensitive.  So you should use "GPSLatitude", not "GPSlatitude".  In the ValueConv expression, $val represents the numerical value (as with -n), and this is what you need.

To extract the components of the date:

   ValueConv => '$val =~ /^(\d{4}):(\d{2}):(\d{2})/ ? $1 : undef',  # year
   ValueConv => '$val =~ /^(\d{4}):(\d{2}):(\d{2})/ ? $2 : undef',  # month
   ValueConv => '$val =~ /^(\d{4}):(\d{2}):(\d{2})/ ? $3 : undef',  # day


Of course, you'll need to create a separate user-defined tag for each of these conversions.

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

flightfollowing

Phil, thanks so much, I would have been struggling with that for a long time. You need a 'donate' option here to pay for some of your time!

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