News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Getting GPS data

Started by pizzipie, December 31, 2016, 03:53:02 PM

Previous topic - Next topic

pizzipie

Hi,

The following code extracts GPSLatitude and GPSLongitude but not all GPS info from EXIF:

  eval('$array=' . `exiftool -c "%+6f" -EXIF:GPS -GPSLatitude -GPSLongitude -php {$filename}`);

Output:

Array
(
    [0] => Array
        (
            [SourceFile] => IMG_0743.JPG
            [GPSLatitude] => +48.274425
            [GPSLongitude] => -116.543817
        )

)

If I use:
                eval('$array=' . `exiftool -c "%+6f" -GPSInfo: -php {$filename}`);

Output:

Warning: Invalid tag name 'GPSInfo:' - IMG_0743.JPG
Array
(
    [0] => Array
        (
            [SourceFile] => IMG_0743.JPG
        )

If -EXIF:GPS is used alone:

Output:

Array
(
    [0] => Array
        (
            [SourceFile] => IMG_0743.JPG
        )

)

)

What would be proper to show ALL GPS data for this image.

Here is part of EXIF:

            [GPSAltitude] => 629.3 m Above Sea Level
            [GPSDateTime] => 2015:08:16 23:14:59.32Z
            [GPSLatitude] => +48.274425
            [GPSLongitude] => -116.543817
            [GPSPosition] => +48.274425, -116.543817

Thanks R

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

pizzipie

Thank you Phil,

                eval('$array=' . `exiftool -c "%+6f" -a -gps:all -php {$filename}`);
Produces:
Array
(
    [0] => Array
        (
            [SourceFile] => IMG_0743.JPG
            [GPSLatitudeRef] => North
            [GPSLongitudeRef] => West
            [GPSAltitudeRef] => Above Sea Level
            [GPSTimeStamp] => 23:14:59.32
            [GPSSpeedRef] => km/h
            [GPSSpeed] => 0
            [GPSImgDirectionRef] => True North
            [GPSImgDirection] => 286.3066667
            [GPSDestBearingRef] => True North
            [GPSDestBearing] => 106.3066667
            [GPSDateStamp] => 2015:08:16
        )

)


Any idea why GPSLatitude and GPSLongitude and GPSAlitude are not here?

When I run this on the command line:

  exiftool -c "%+6f" -a -gps:all IMG_0743.JPG

Output is:
GPS Latitude Ref                : North
GPS Latitude                    : 48.274425
GPS Longitude Ref               : West
GPS Longitude                   : 116.543817
GPS Altitude Ref                : Above Sea Level
GPS Altitude                    : 629.3584906 m
GPS Time Stamp                  : 23:14:59.32
GPS Speed Ref                   : km/h
GPS Speed                       : 0
GPS Img Direction Ref           : True North
GPS Img Direction               : 286.3066667
GPS Dest Bearing Ref            : True North
GPS Dest Bearing                : 106.3066667
GPS Date Stamp                  : 2015:08:16


Thanks,

R

Phil Harvey

Ah right.  Hmmm.  This is as designed.  For the -php and -json options, this applies:

            The -a option is implied if the -g or -G options
            are used, otherwise it is ignored and duplicate tags are
            suppressed.


But I have to think about this because the behaviour isn't what you would want in this case.  For now, you can avoid the problem by adding -G.

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

pizzipie

I tried:
exec ( 'exiftool -c "%+6f" -a -gps:all '.$filename, $array);

output:


Array
(
    [0] => GPS Latitude Ref                : North
    [1] => GPS Latitude                    : 48.274425
    [2] => GPS Longitude Ref               : West
    [3] => GPS Longitude                   : 116.543817
    [4] => GPS Altitude Ref                : Above Sea Level
    [5] => GPS Altitude                    : 629.3584906 m
    [6] => GPS Time Stamp                  : 23:14:59.32
    [7] => GPS Speed Ref                   : km/h
    [8] => GPS Speed                       : 0
    [9] => GPS Img Direction Ref           : True North
    [10] => GPS Img Direction               : 286.3066667
    [11] => GPS Dest Bearing Ref            : True North
    [12] => GPS Dest Bearing                : 106.3066667
    [13] => GPS Date Stamp                  : 2015:08:16
)


This has all GPS but in different format. Is this php or exiftool differences?

Thanks again,

R

pizzipie

UPDATE:

I tried using -G and -g with exec() and the results leave out GPSLatitude, GPSLonitude, and GPSAltitude.

pizzipie

UPDATE 2 - Added -g to -a

exec( 'exiftool -c "%+6f" -a -g -gps:all '.$filename, $array); 

Output:
Array
(
    [0] => ---- EXIF ----
    [1] => GPS Latitude Ref                : North
    [2] => GPS Latitude                    : 48.274425
    [3] => GPS Longitude Ref               : West
    [4] => GPS Longitude                   : 116.543817
    [5] => GPS Altitude Ref                : Above Sea Level
    [6] => GPS Altitude                    : 629.3584906 m
    [7] => GPS Time Stamp                  : 23:14:59.32
    [8] => GPS Speed Ref                   : km/h
    [9] => GPS Speed                       : 0
    [10] => GPS Img Direction Ref           : True North
    [11] => GPS Img Direction               : 286.3066667
    [12] => GPS Dest Bearing Ref            : True North
    [13] => GPS Dest Bearing                : 106.3066667
    [14] => GPS Date Stamp                  : 2015:08:16
)


Has all the data but -c "%+.6f" doesn't produce '+' or '-'

R

Hayo Baan

Ah, I see what's happening, the -c formatting option seems to only apply to the composite versions of the GPS tags, and those are not the tags that get extracted when you specify -GPS:all. Then only the true GPS tags get extracted.

I suggest you use "-gps*" instead (quotes are necessary on Mac/Linux, optional on Windows). This will get you all tags that start with gps. If this gets you tags you don't want to see, simply exclude them with --tagname. For instance, this command will get you all info but skips the exif ones for where the composite is what you wanted:
exiftool -c "%+6f" -G0:1 -a -"GPS*" "--EXIF:GPS:GPS*tude*" FILE
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Yes.  The EXIF GPS coordinates are not signed.  This is the whole purpose of the Composite GPS tags (to combine the coordinates with their reference hemispheres).  I think you can achieve Hayo's suggestion more simply by just replacing -gps:all with "-gps*" in your original command.  (No need for -G, -a or --EXIF:GPS:GPS*tude.)

This will take the Composite tags if they exist, which seems to be what you want.

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

pizzipie

Thanks,

I am learning! Slowly.

For anyone who might be interested here is what I've come up with.

PHP Code:
<?php

error_reporting (E_ALL ^ E_NOTICE);

// ==============  declarations  =============

$filename="IMG_0743.JPG";
$nav=Array();
$MTOFT=3.280840;  // constant to convert meters to feet

/* ================== Example of Exif read of GPS Data ==================
   NOTE: PHP command "exif_read_data()" does not work  ================== 
         PHP command  "eval() is supposedly a bad command ===============                 
====================================================================== */


//eval('$nav2=' . `exiftool -c "%+.6f"  -gps* -php {$filename}`);    For Test Only

exec( 'exiftool -c "%+.6f" "-gps*" -a -g  -s '.$filename, $nav);

print_r($nav);
               
$v=explode(":",$nav[1]); // GPSLatitude Ref tag
$w=explode(":",$nav[3]); // GPSLongitude Ref tag
$x=explode(":",$nav[2]); // GPSLatitude tag
$y=explode(":",$nav[4]); // GPSLongitude tag
$z=explode(":",$nav[6]); // GPSAltitude tag
$lat=(float)$x[1]; // convert to numbers
$lng=(float)$y[1];
$alt=(float)$z[1];

trim($v[1])=="South" ? $latitude=$lat*-1  : $latitude=$lat;   // South is -Latitude
trim($w[1])=="West"  ? $longitude=$lng*-1 : $longitude=$lng;  // West is -Longitude

$altitude=$alt*$MTOFT; // convert altitude from meters to feet

echo "\nLatitude ".$latitude."\n";
echo "Longitude ".$longitude."\n";
echo "Altitude ".$altitude."\n";


echo "\n =========================== End Example ================================ \n\n";

?>


Output:
rick@rick-Latitude-E6510:~/Pictures/exifPlay$ php -f getExif-GPS.php
Array
(
    [0] => ---- EXIF ----
    [1] => GPSLatitudeRef                  : North
    [2] => GPSLatitude                     : 48.274425
    [3] => GPSLongitudeRef                 : West
    [4] => GPSLongitude                    : 116.543817
    [5] => GPSAltitudeRef                  : Above Sea Level
    [6] => GPSAltitude                     : 629.3584906 m
    [7] => GPSTimeStamp                    : 23:14:59.32
    [8] => GPSSpeedRef                     : km/h
    [9] => GPSSpeed                        : 0
    [10] => GPSImgDirectionRef              : True North
    [11] => GPSImgDirection                 : 286.3066667
    [12] => GPSDestBearingRef               : True North
    [13] => GPSDestBearing                  : 106.3066667
    [14] => GPSDateStamp                    : 2015:08:16
    [15] => ---- Composite ----
    [16] => GPSAltitude                     : 629.3 m Above Sea Level
    [17] => GPSDateTime                     : 2015:08:16 23:14:59.32Z
    [18] => GPSLatitude                     : +48.274425
    [19] => GPSLongitude                    : -116.543817
    [20] => GPSPosition                     : +48.274425, -116.543817
)

Latitude 48.274425
Longitude -116.543817
Altitude 2064.8245103001

=========================== End Example ================================


I could have used the composite info as in array[16-20] however I just discovered how to get ALL the information in the last two replys.

Thanks again for your help Phil and Hayo

R

delovelady

Quote from: pizzipie on January 01, 2017, 04:28:55 PM$v=explode(":",$nav[1]); // GPSLatitude Ref tag
$w=explode(":",$nav[3]); // GPSLongitude Ref tag
$x=explode(":",$nav[2]); // GPSLatitude tag
$y=explode(":",$nav[4]); // GPSLongitude tag
$z=explode(":",$nav[6]); // GPSAltitude tag
$lat=(float)$x[1]; // convert to numbers
$lng=(float)$y[1];
$alt=(float)$z[1];

While the above probably works, it's a little scary in that there are assumptions that the tool will always return the same data in the same order, with no new information interspersed.  Possibly safe, but I might suggest the use of the -php flag as in the following example for safer code.  Note the line  starting with '$assocArray =' is all it takes to make this into a [significantly safer] associative array (when the -php flag is used).

exec( 'exiftool -c "%+.6f" "-gps*" -a -g -php -s '.$filename, $nav);
if (is_array($nav)) { // This will be true unless something is terribly wrong....
$assocArray = eval('return ' . implode('', $nav)) ;

// Now, $assocArray[0] is an associative array addressible by tag name. 
// So, for example, $assocArray[0]['EXIF']['GPSLatitudeRef'] would be 'North' in this example.
//                  $assocArray[0]['EXIF']['GPSLatitude'] would be value 48.274425
// And so on.
}