Author Topic: Photo GPS Geolocation GeoCaching Mapping Help  (Read 1332 times)

0 Members and 1 Guest are viewing this topic.

Offline edyTopic starter

  • Super Contributor
  • ***
  • Posts: 2385
  • Country: ca
    • DevHackMod Channel
Photo GPS Geolocation GeoCaching Mapping Help
« on: July 29, 2018, 10:52:00 pm »
I am trying to decypher some EXIF data from photos on a Linux machine. Using a program called "identify" in Ubuntu which I believe is installed as part of the ImageMagick package (https://www.imagemagick.org) , I tried a few samples online and here is one example that I got the output from, taken with an iPhone:

snippet...

Code: [Select]
    exif:ExifVersion: 48, 50, 50, 49
    exif:GPSAltitude: 43315/204
    exif:GPSAltitudeRef: 0
    exif:GPSImgDirection: 27489/158
    exif:GPSImgDirectionRef: T
    exif:GPSInfo: 638
    exif:GPSLatitude: 35/1, 323/100, 0/1
    exif:GPSLatitudeRef: N
    exif:GPSLongitude: 85/1, 1871/100, 0/1
    exif:GPSLongitudeRef: W
    exif:GPSTimeStamp: 23/1, 9/1, 1303/100
    exif:Make: Apple
    exif:Model: iPhone 5
  Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org


First, I'm not sure how to properly read that GPS data:

    exif:GPSLatitude: 35/1, 323/100, 0/1
    exif:GPSLatitudeRef: N
    exif:GPSLongitude: 85/1, 1871/100, 0/1
    exif:GPSLongitudeRef: W

It seems to be 35N, 85W for sure (degrees), which puts it somewhere in Tennessee. But then I am not sure how to interpret the additional latitude info 323/100, 0/1, and longitude 1871/100, 0/1. This does not appear to be minutes, seconds or at least not in the normal format. The other question is, how accurate would that data be? Is it obfuscated on purpose? Would it be at least close or does the phone actually scramble it normally on purpose?

Second, I am wondering how to take a folder worth of images and have this program systematically go through each file, pull the GPS data and create some kind of table (like an output file, comma-delimited) with the name of the file, and the GPS coordinates/time? This way I can create some kind of path on a map and have photos tagged to each waypoint. Even just pulling all the GPS coordinates out into a table would be useful so I can see which images have coordinates and which don't. Any ideas how to decyper that GPS information or do bulk processing of images in Ubuntu? There may be another program that does this that I don't know about. Thanks!
« Last Edit: July 29, 2018, 10:57:51 pm by edy »
YouTube: www.devhackmod.com LBRY: https://lbry.tv/@winegaming:b Bandcamp Music Link
"Ye cannae change the laws of physics, captain" - Scotty
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: Photo GPS Geolocation GeoCaching Mapping Help
« Reply #1 on: July 29, 2018, 11:29:08 pm »
http://www.ridgesolutions.ie/index.php/2015/03/05/geotag-exif-gps-latitude-field-format/

Also, depending on where you use the GPS coordinates, you may have to correct them to your local grid system.
 
The following users thanked this post: edy

Offline tsman

  • Frequent Contributor
  • **
  • Posts: 599
  • Country: gb
Re: Photo GPS Geolocation GeoCaching Mapping Help
« Reply #2 on: July 29, 2018, 11:39:22 pm »
    exif:GPSLatitude: 35/1, 323/100, 0/1
    exif:GPSLatitudeRef: N
    exif:GPSLongitude: 85/1, 1871/100, 0/1
    exif:GPSLongitudeRef: W
It is listing it as numerator/denominator due to how it is stored in the EXIF tag.

35/1 = 35
323/100 = 3.23
0/1 = 0

81/1 = 81
1871/100 = 18.71
0/1 = 0

35°3.23′0″N 81°18.71′0″W

You may need to correct it because it may be using the GPS datum which is WGS84. Not sure it if has already done it or not for the EXIF data.

The other question is, how accurate would that data be? Is it obfuscated on purpose? Would it be at least close or does the phone actually scramble it normally on purpose?
The camera itself should put accurate coordinates in unless you tell it otherwise. If it was automatically uploaded to an online photo sharing service and you downloaded it via the web then it may strip out the GPS coordinates entirely or obfuscate it.
 
The following users thanked this post: edy

Offline edyTopic starter

  • Super Contributor
  • ***
  • Posts: 2385
  • Country: ca
    • DevHackMod Channel
Re: Photo GPS Geolocation GeoCaching Mapping Help
« Reply #3 on: July 29, 2018, 11:46:14 pm »
Update:

I figured out how to apply a command to each file in BASH shell like this:

Code: [Select]
for f in *.jpg ; do identify -verbose "$f" | grep "Image:\|exif:GPS" ; done

So this takes every file (for f in *.jpg), and outputs the exif data and then grep only shows the file name ("Image:") OR (by way of the \| operator) the GPS exif data. So I get a string of data which I could dump to an output text file using the ">". At this point, I need some way to turn this long list into tabulated semicolon-delimited lines. For example, the output file I get with the above command looks something like this:

Code: [Select]
Image: fiename1.jpg
     exif:GPSLatitude: 35/1, 2/1, 5926/100
     exit:GPSLongitude: 85/1, 18/1, 5373/100
Image: filename2.jpg
     exif:GPSLatitude: 35/1, 2/1, 5926/100
     exit:GPSLongitude: 85/1, 18/1, 5373/100
.
.
...etc...

What I need is to take that file and make it so.....

filename1.jpg;  35/1, 2/1, 5926/100;  85/1, 18/1, 5373/100
filename2.jpg;  35/1, 2/1, 5926/100;  85/1, 18/1, 5373/100
...etc...

That I can input into Excel and then do conversions and so on.  Apparently "awk" has the ability to do this... I will look into this further.

UPDATE:

The "awk" indeed lets me concatenate to one line, but it is not putting a carriage-return at the end of the line. For example, this seems to make everything appear on one line:

Code: [Select]
for f in *.jpg ; do identify -verbose "$f" | grep "Image:\|exif:GPSLatitude\|exif:GPSLongitude" | awk '{print}' ORS='; '; done

It outputs the name of the file (Image:), and the GPSLatitude and GPSLatitudeRef data, and GPSLongitude and GPSLongitudeRef data all on a line. But I need at the end of it all to insert a CR/LF or something and it is not doing that. Somehow I need that added before the next "do loop".
« Last Edit: July 29, 2018, 11:56:49 pm by edy »
YouTube: www.devhackmod.com LBRY: https://lbry.tv/@winegaming:b Bandcamp Music Link
"Ye cannae change the laws of physics, captain" - Scotty
 

Offline tsman

  • Frequent Contributor
  • **
  • Posts: 599
  • Country: gb
Re: Photo GPS Geolocation GeoCaching Mapping Help
« Reply #4 on: July 30, 2018, 12:11:51 am »
The easiest/cleanest option is going to be just writing a short script in your favourite language that has an EXIF library you can use.

Install the ExifTool package for Perl. Zero error checking. Massage the output as appropriate.
Code: [Select]
#!/usr/bin/perl
use Image::ExifTool ':Public';

@files = <"*.jpg">;

foreach $file (@files) {
  $metadata = ImageInfo $file;

  print $file, ", ", $metadata->{GPSLatitude}, ", ", $metadata->{GPSLongitude}, "\n";
}
« Last Edit: July 30, 2018, 12:26:31 am by tsman »
 

Offline edyTopic starter

  • Super Contributor
  • ***
  • Posts: 2385
  • Country: ca
    • DevHackMod Channel
Re: Photo GPS Geolocation GeoCaching Mapping Help
« Reply #5 on: July 30, 2018, 12:31:41 am »
The easiest/cleanest option is going to be just writing a short script in your favourite language that has an EXIF library you can use.

Yes you are likely correct. I did figure out a way to do it all in one line...  :-+    Pulled out all my linux knowledge. By some miracle Linux lets you combine all these text filter/manipulators, it's quite amazing that it actually works:

Code: [Select]
for f in *.jpg ; do identify -verbose "$f" | grep "Image:\|exif:GPSLatitude\|exif:GPSLongitude" | awk '{print}' ORS='; ' | sed "$ s/$/\n/"; done > output.txt


Ok, so let's chop this up into each piece...

Code: [Select]
for f in *.jpg ;
   do identify -verbose "$f"
      | grep "Image:\|exif:GPSLatitude\|exif:GPSLongitude"
      | awk '{print}' ORS='; '
      | sed "$ s/$/\n/";
   done
> output.txt

Line 1. Go through all of the files named *.jpg.
Line 2. Do the command "identify" - verbose" on that file name.
Line 3. grep: display only lines with "Image:", "GPSLatitude" and "GPSLongitude" in them.
Line 4. awk: prints them all to the same line, separates records by "; " symbol.
Line 5. sed: adds a CR-LF to the end of the line (basically takes full output of awk and simply adds CR-LF).
Line 6. done refers to the "do" command in line 2.
Line 7. redirect all the output to "output.txt" file.

The resulting output looks like this:

Code: [Select]
Image: 1.jpg;     exif:GPSLatitude: 35/1, 2/1, 5990/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5540/100;     exif:GPSLongitudeRef: W;
Image: 2.jpg;     exif:GPSLatitude: 35/1, 2/1, 5420/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5380/100;     exif:GPSLongitudeRef: W;
Image: 3.jpg;     exif:GPSLatitude: 35/1, 2/1, 5620/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5440/100;     exif:GPSLongitudeRef: W;
Image: 4.jpg;     exif:GPSLatitude: 35/1, 2/1, 5720/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5680/100;     exif:GPSLongitudeRef: W;
Image: 5.jpg;     exif:GPSLatitude: 35/1, 2/1, 5990/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5390/100;     exif:GPSLongitudeRef: W;
Image: 6.jpg;     exif:GPSLatitude: 35/1, 2/1, 5996/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5373/100;     exif:GPSLongitudeRef: W;
Image: 7.jpg;     exif:GPSLatitude: 35/1, 2/1, 5346/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5412/100;     exif:GPSLongitudeRef: W;
Image: 8.jpg;     exif:GPSLatitude: 35/1, 2/1, 5235/100;     exif:GPSLatitudeRef: N;     exif:GPSLongitude: 85/1, 18/1, 5320/100;     exif:GPSLongitudeRef: W;

Now to go back and figure out what this means, which will hopefully allow me to properly convert the data in Excel:

http://www.ridgesolutions.ie/index.php/2015/03/05/geotag-exif-gps-latitude-field-format/

Also, depending on where you use the GPS coordinates, you may have to correct them to your local grid system.

EDIT:

OK, the above article explains it very nicely. Thank you. It seems that the EXIF protocol allows you to specify how you want the DMS to be split up among the 6 "4-byte" values. For example, you have fractions A/B C/D E/F where A/B indicates deg, C/D is min, E/F is sec. The fractions give you the actual value. Some devices decide to ignore E/F completely and just put 0/1. In that case, the fraction for C/D is the min with decimal places (e.g. if C/D is 4044/100 then it becomes 40.44 min). In that case, A/B may be 52/1 4044/100 0/1 = 52 deg, 40.44 min.  In the case where the software includes numbers for all of the 3 fractions A/B, C/D and E/F, then it is as follows:  32/1 4/1 4044/100 means 32 deg, 4 min, and 40.44 sec. To make this a decimal degree only, then 4 min + 40.44 sec/60 sec/min = 4 + 0.674 = 4.674 min. Then 32 deg + 4.674 min/60 min/deg = 32.0779 deg. Then in Google I just map degLat,degLon like this:  32.4232N,65.32423W (or whatever).

Once in Excel I can pick apart the strings and do the appropriate math calculations and add up the fractions to come up with the decimal degree format, hopefully not to difficult to parse out the individual numbers for A, B, C, D, E and F.
« Last Edit: July 30, 2018, 01:17:17 am by edy »
YouTube: www.devhackmod.com LBRY: https://lbry.tv/@winegaming:b Bandcamp Music Link
"Ye cannae change the laws of physics, captain" - Scotty
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf