-1

I have 4000 .jpeg image files to which I want to add Latitude & Longitude using exiftool. I have a text file having :

  • First Column = Image filenames serial-wise from 1 to 4000
  • Second Column = Latitude
  • Third Column = Longitude

How do I add longitudes and latitudes to images with some script ?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
rehman
  • 101
  • 7
  • What you have tried so far ? – C0deDaedalus May 26 '18 at 12:52
  • Is the text file a CSV file? If so, you could use exiftool's `-csv` option, though it might take some minor modifications to the header row of the file. – StarGeek May 26 '18 at 17:29
  • Stack Overflow is not a code writing service. Please show your code. Since Stack Overflow hides the Close reason from you: *Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/).* – jww May 26 '18 at 22:45

1 Answers1

-1

I have not tried the script, so there is obviously some scope for optimization. For the time being you can try this.

Considering file named coordinates have the columns as described in the question, I have written this script accordingly.

#!/bin/bash

# Loop for every line in the coordinates file
cat coordinates | while IFS= read -r line
do

    # Get Image name from Ist, Latitude from 2nd & Longitude from 3rd column.
    IMAGE=`echo "$line" | awk '{print $1}'` 
      LAT=`echo "$line" | awk '{print $2}'` 
     LONG=`echo "$line" | awk '{print $3}'`

    # Assign variables values into "exiftool" command
    exiftool -exif:gpslatitude="$LAT" -exif:gpslatituderef=S -exif:gpdlongitude="$LONG" -exif:gpslongituderef=E "$IMAGE"

done

Some points to consider :

  1. If exif tags don't work for you, you may use XMP tags. In that case the command-line would be like this :

    exiftool -XMP:GPSLatitude="$LAT" -XMP:GPSLongitude="$LONG"  -GPSLatitudeRef="South" -GPSLongitudeRef="East" "$IMAGE"
    
  2. If you don't have References values for GPSLatitudeRef & GPSLongitudeRef positions, just use -P, and It should run fine :

    exiftool -XMP:GPSLatitude="$LAT" -XMP:GPSLongitude="$LONG" -P "$IMAGE"
    

    -P option preserves and overwrites the values for tags passed to it, ignoring the rest of tags that are also needed.

  3. If you wish to add more or less tags, please refer to GPS Tags.

Feel free to add in more details.

C0deDaedalus
  • 361
  • 1
  • 4
  • 19
  • A couple of issues: [`-P` option](https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#P--preserve) only preserves the filesystem modification date/time (`FileModifyDate`). It has no affect on any other tag. If you're setting the `XMP:GPSLatitude/Longitude`, there's no need to set the ref values, as the directional reference are included in the XMP tag. Finally, rather than hard coding the directional references, you can just assign the `$LAT` and `$LONG` variables to them. Exiftool will figure out the reference direction and properly update them. – StarGeek May 26 '18 at 17:36
  • I have did as above said and then runned the command exiftool -l *jpg I am able to see lat and long in meta-data. But when uploading the photo in ArcGIS it not showing the location on map.@StarGeek – rehman May 28 '18 at 06:04
  • In that case, there maybe an issue with file formatting or encoding or such as needed by GIS. Would advise you to post a question for issues you are facing on [GIS StackEx](https://gis.stackexchange.com/) – C0deDaedalus May 28 '18 at 06:12