Photo GPS Geolocation GeoCaching Mapping Help - Page 1
Forum section: electronics / general

author: edy
author_rank: Super Contributor
timestamp: July 29, 2018, 10:52:00 pm
content: 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:exif:ExifVersion: 48, 50, 50, 49exif:GPSAltitude: 43315/204exif:GPSAltitudeRef: 0exif:GPSImgDirection: 27489/158exif:GPSImgDirectionRef: Texif:GPSInfo: 638exif:GPSLatitude: 35/1, 323/100, 0/1exif:GPSLatitudeRef: Nexif:GPSLongitude: 85/1, 1871/100, 0/1exif:GPSLongitudeRef: Wexif:GPSTimeStamp: 23/1, 9/1, 1303/100exif:Make: Appleexif:Model: iPhone 5Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.orgFirst, I'm not sure how to properly read that GPS data:exif:GPSLatitude: 35/1, 323/100, 0/1exif:GPSLatitudeRef: Nexif:GPSLongitude: 85/1, 1871/100, 0/1exif:GPSLongitudeRef: WIt 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!

author: Andy Watson
author_rank: Super Contributor
timestamp: July 29, 2018, 11:29:08 pm
content: 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.

author: tsman
author_rank: Frequent Contributor
timestamp: July 29, 2018, 11:39:22 pm
content: Quote from: edy on July 29, 2018, 10:52:00 pmIt is listing it as numerator/denominator due to how it is stored in the EXIF tag.35/1 = 35323/100 = 3.230/1 = 081/1 = 811871/100 = 18.710/1 = 035°3.23′0″N 81°18.71′0″WYou 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.Quote from: edy on July 29, 2018, 10:52:00 pmThe 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.

author: edy
author_rank: Super Contributor
timestamp: July 29, 2018, 11:46:14 pm
content: Update:I figured out how to apply a command to each file in BASH shell like this:Code:for f in *.jpg ; do identify -verbose "$f" | grep "Image:\|exif:GPS" ; doneSo 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:Image: fiename1.jpgexif:GPSLatitude: 35/1, 2/1, 5926/100exit:GPSLongitude: 85/1, 18/1, 5373/100Image: filename2.jpgexif:GPSLatitude: 35/1, 2/1, 5926/100exit: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/100filename2.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:for f in *.jpg ; do identify -verbose "$f" | grep "Image:\|exif:GPSLatitude\|exif:GPSLongitude" | awk '{print}' ORS='; '; doneIt 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".

author: tsman
author_rank: Frequent Contributor
timestamp: July 30, 2018, 12:11:51 am
content: 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:#!/usr/bin/perluse Image::ExifTool ':Public';@files = <"*.jpg">;foreach $file (@files) {$metadata = ImageInfo $file;print $file, ", ", $metadata->{GPSLatitude}, ", ", $metadata->{GPSLongitude}, "\n";}

author: edy
author_rank: Super Contributor
timestamp: July 30, 2018, 12:31:41 am
content: Quote from: tsman on July 30, 2018, 12:11:51 amYes 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:for f in *.jpg ; do identify -verbose "$f" | grep "Image:\|exif:GPSLatitude\|exif:GPSLongitude" | awk '{print}' ORS='; ' | sed "$ s/$/\n/"; done > output.txtOk, so let's chop this up into each piece...Code:for f in *.jpg ;do identify -verbose "$f"| grep "Image:\|exif:GPSLatitude\|exif:GPSLongitude"| awk '{print}' ORS='; '| sed "$ s/$/\n/";done> output.txtLine 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: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:Quote from: Andy Watson on July 29, 2018, 11:29:08 pmEDIT: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.