ExifTool, Powershell, Cmd line – adding GPS

ExifTool, Powershell, Cmd line – adding GPS

So you’ve got some photos, those photos do not have any location data. You have some data and you wish to automate adding that data to your photos.
The concept is simple, yet there are numerous hurdles to overcome.

I’ll highlight some of the issues I hit along my journey so you do not have to. See previous post which is another hurdle I had to overcome.

It works on the command line

First step is to get the Exiftool from here if you wish to follow along. This does the actual adding, you just need to know what and how to call it.

Next up, is that you are going to test it working on a single image and most of the examples I was reading involved the command line. So off I went.

This is the XML node containing the data

<trkpt lat="56.9359839838" lon="-4.4651045874">

So you pull out the latitude and longitude and come up with the following:

exiftool -exif:gpslongitude=-4.4651045874 -exif:gpslatitude=56.9359839838 -GPSAltitude=30.42 DSC00320.JPG

Important to note that I’ve copied the exiftool.exe into the same folder as the image and the above command is run from that same folder. Means you don’t have to worry about paths. Makes it simple for initial start up.

So I run the above, it works – sort of! No errors, I take the image, drop it into either Flickr or a free app that shows the location the photo has been tagged with. Hmmmm, it’s not right. That location is in Scotland, but the map is showing it as somewhere in the middle of the North Sea!

Reason it failed is that GPSLatitude/GPSLongitude needs a reference to it’s place in the world, as in which quadrant it’s in. So that would be N/S/E/W. But I do not have that data. In my case the data is negative, so that means it’s West and not East. But this command only takes the number as if it was positive! It completely ignores that fact I gave it a negative value!

Next option

So exif failed. Googling, I can see that if I use the xmp commands, they can handle negative values, as in it does not require the reference values of N/S/E/W

exiftool -xmp:gpslongitude=-4.4651045874 -xmp:gpslatitude=56.9359839838 -GPSAltitude=30.42 DSC00320.JPG 

Again no errors. I load the file into GeoSetter and it shows me exactly where I expect the photos location to be. Wonderful. It worked then. NOPE!!!!

I load the exact same file into Flickr, and yet again, the same as the first command it places the photo’s location into the North Sea! 😕 Trying this in various ways and same thing each time. Works in GeoSetter, but not in Flickr. What on earth is going on???

Debugging/Comparing tags

Firstly I went to look at the GPS location while inside of GeoSetter and if I tried to change it there, it gave me the following warning.

After setting this in GeoSetter, the file with no changes to GPS location then worked in Flickr!

So now that it worked in both GeoSetter and Flickr I presumed that the reason it failed initially in Flickr was due to some timestamp/date issues. Perhaps Flickr being a bit more professional than a free app, it respected the rules in a stricter fashion. WRONG, the reason it failed was not down to the timestamp! On adding the timestamp, Geosetter also updated the geotags which made it work in Flickr.

Had I known this command at the start which outputs exif tags in groups that would have help hugely in debugging the situation.

exiftool -a -G1 -s E:\CameraAddGPS\TestFolder\before\photos\DSC00939.JPG

Correct command to insert GPS with only lat/lon

exiftool -GPSLatitude*=56.9359839838 -GPSLongitude*=-4.4651045874 -GPSAltitude*=30.42 DSC00320.JPG 

You can see that the parameters include a wildcard and what that allows is to only give the lat/lon and it will then work out the N/E/S/W based on the -ve or +ve values given. 👌

Now that works in both Flickr and Geosetter. Brilliant 😍
Next up is to figure out how to do so from within Powershell. (see my next post, coming soon)

Additional info

Just a FYI, if you run the above command to output the grouped data on the files, the below is what you see. The text on the left if from the data of the file that works in all places (Flickr and Geosetter), and the text on the right is from the file that only worked in Geosetter.

You can see that both have the correct data, but the one on the left (which works in all places) has the data inside the main GPS tagged group, whereas the one on the right has some different Composite data and XMP-exif data which isn’t standard enough for Flickr to pick up.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.