ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: bibinwilson on January 25, 2017, 08:50:30 AM

Title: How to dynamically update the file name
Post by: bibinwilson on January 25, 2017, 08:50:30 AM
I have a bunch(around 400) jpeg image that is obtained from FLIR camera. Along with that images I collected the GPS coordinates also. Now I'm trying to take the GPS latitude and longitude to the metadata of the image.

I wrote a program in R programming language to find the GPS location of each image with respect to the time(when ever the GPS time and the camera time matches, I took that coordinates).

ie, for a particular image, I have GPSLatitude=19.33423 and GPSLongitude=72.090834

But now I need to add those exact GPS location to the image. I'm able to do it using the terminal with the following command
exiftool -GPSLatitude=19.131843 -GPSLongitude=72.91783 20161013_121101.jpg
where 20161013_121101.jpg is the image name.

But in R program, I need to take a batch of jpeg images and need to edit the GPS location, so  I wrote it as

output <- system("exiftool -GPSLatitude=19.131843 -GPSLongitude=72.91783 aa")     values are considered as an example

where aa is dynamically changed with the name of jpeg files. Now the problem is exiftool is considering aa as the filename and showing an error
Error: File not found - aa

I'm using Mac osX sierra.

Can anyone help me.

Thanks
Title: Re: How to dynamically update the file name
Post by: Phil Harvey on January 25, 2017, 08:56:07 AM
ExifTool will do the time interpolation for you if the GPS track is stored in a recognized format.  See the -geotag option for details.

But to fix your R problem, try specifying the full path to the file instead of just "aa".  I don't know what the working directory is set to when you shell out a command from R, so specifying the full path avoids this question.

- Phil
Title: Re: How to dynamically update the file name
Post by: bibinwilson on January 25, 2017, 09:10:06 AM
aa itself is having the full path
ie I'm dynamically putting the pathname to aa=/Users/bibinwilson/Dropbox/Research/LabWork/test/20161013_121103.jpg
in the next iteration, it will be aa=/Users/bibinwilson/Dropbox/Research/LabWork/test/20161013_121104.jpg etc

is there any provision to do like this? first time I'm using exiftool. please help me
Title: Re: How to dynamically update the file name
Post by: Phil Harvey on January 25, 2017, 09:16:03 AM
Then I don't understand why ExifTool can't find the file.

Quote from: bibinwilson on January 25, 2017, 09:10:06 AM
is there any provision to do like this?

I don't know what you mean.

- Phil
Title: Re: How to dynamically update the file name
Post by: bibinwilson on January 25, 2017, 09:17:42 AM
I mean, is it possible to do like that. Otherwise can I do it in any other alternative manner?
Title: Re: How to dynamically update the file name
Post by: Phil Harvey on January 25, 2017, 09:24:59 AM
To do like what?  Iterate over multiple files?  Sure.
Title: Re: How to dynamically update the file name
Post by: bibinwilson on January 25, 2017, 09:31:30 AM
May I know how it's possible?
Title: Re: How to dynamically update the file name
Post by: Phil Harvey on January 25, 2017, 09:35:17 AM
exiftool -geotag track.gpx DIR
Title: Re: How to dynamically update the file name
Post by: StarGeek on January 25, 2017, 11:43:07 AM
QuoteNow the problem is exiftool is considering aa as the filename and showing an error
Error: File not found - aa

I know nothing about R (didn't even know about its existence) but it seems to me that your command isn't passing the value of variable aa, it's passing the constant "aa". 

A quick search and I came across this StackOverflow (//http://) answer which seems to indicate that this is the problem.  It looks like your code should be

output <- system(sprintf("exiftool -GPSLatitude=19.131843 -GPSLongitude=72.91783 %s",aa))
or
output <- system(paste("exiftool -GPSLatitude=19.131843 -GPSLongitude=72.91783 ", aa))     

Having said that, if your coordinate data is in a geotrack format that exiftool already understands, you're going to see an huge increase in speed if you run a single exiftool command like Phil suggests rather than loop and execute exiftool ever time (see Common Mistake 3 (http://www.exiftool.org/mistakes.html#M3)).

Also, if any of your gps data is negative (Southern or Western  hemisphere), then you also need to set the GPSLatitudeRef and GPSLongitudeRef tags, otherwise your results will show up in the wrong part of the world.
Title: Re: How to dynamically update the file name
Post by: bibinwilson on January 25, 2017, 02:36:19 PM
Thank you so much. You saved my life. Can you help me out in one more thing. I tried a lot. Now I removed the exact values given with a variable name
ie I stored 19.131843=q and p=72.91783. I did this to make dynamic nature, ie, p and q value will change in every iteration.
so my code looks like :

output <- system(sprintf("exiftool -GPSLatitude=q -GPSLongitude=p %s",aa))

But now GPS (lat lon) values changes back to (0 0)

Is there any way to rectify this.

Thank you
Title: Re: How to dynamically update the file name
Post by: Hayo Baan on January 25, 2017, 02:52:56 PM
This is the same problem as before: The p and q in your solution are taken as literal, not the value of variable. Replace them with %f (or whatever R uses to denote a floating point) and replace aa with q, p, aa.

Note that I have never programmed in R before, but this is a basic programming thing (i.e. the difference between variables and string literals).
Title: Re: How to dynamically update the file name
Post by: StarGeek on January 25, 2017, 02:54:18 PM
I'm just guessing based upon the link, but try

output <- system(sprintf("exiftool -GPSLatitude=%f -GPSLongitude=%f %s",q,p,aa))
or
output <- system(paste("exiftool -GPSLatitude=",q," -GPSLongitude=",p," ", aa))

Edit: If this works, don't forget to go back to StackOverflow and select the answer.  More sweet internet points for me!  :D
Title: Re: How to dynamically update the file name
Post by: bibinwilson on January 25, 2017, 02:58:35 PM
Thank you sooooooo much guys...... Now I can rest in peace!!!