ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: angelpoo on January 20, 2011, 07:15:12 PM

Title: Extract GPS coordinates for all pictures in one file
Post by: angelpoo on January 20, 2011, 07:15:12 PM
Aloha,

I am looking for a command line that does the following:
Extracts only the GPS lat/long information from all photos in a directory and puts them all in one text file.
Essentially, the txt will have three columns:  The first is the photo name and the second and third will be the lat long.

Can this be done?  I have tried some combinations but failed.  Now I am totally confused.

Thanks in advance for the help!

Chui
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on January 20, 2011, 07:30:32 PM
Hi Chui,

Try this command:

exiftool -filename -gpslatitude -gpslongitude -T DIR > out.txt

where DIR is the name of a directory containing the images (like c:\pictures for example).  Put quotes around the directory name if it contains spaces.

This command will create a tab-delimited file called "out.txt" with your specified columns.

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: angelpoo on January 20, 2011, 07:44:57 PM
Wow!  Thanks Phil!  It worked perfect! 

Is there a way to change those output lat/long into decimal degrees?  And if so, will the conversion cause a loss of precision in the coordinates?

Chui
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on January 20, 2011, 08:43:25 PM
Hi Chui,

Add the -n option to the command to output the coordinates as signed decimal degrees.   In fact, you may gain precision by doing this because the -n value is returned at the full precision available.

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: angelpoo on January 21, 2011, 12:50:21 PM
Thanks Phil for all your help.  I know you hear this often but Exiftool is awesome!  ;D
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on January 21, 2011, 01:34:31 PM
Hi Chui,

Quote from: angelpoo on January 21, 2011, 12:50:21 PM
I know you hear this often but Exiftool is awesome!  ;D

I may have heard it before, but I don't often acknowledge because I'm not very good at accepting praise.  However, it is appreciated.  Thanks. :)
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: PIBO on November 29, 2011, 11:00:16 AM
This also worked great for me! Thanks Phil.

I do have an additional question:

I have a directory/folder that contains a whole bunch of other directories/folders with geotagged photos in them. I'm looking for a quick way, batch style, to have exiftool look through all of the folders and all of the photos within, extract coordinates, and put them in the text file. Is this possible? Could it also label the photos based on which folder they came out of?

Thanks in advance.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on November 29, 2011, 11:39:16 AM
Sure.  The -r option recurses into sub-directories, and just add -directory to output the directory name:

exiftool -filename -directory -gpslatitude -gpslongitude -T -r DIR > out.txt

Or, you could use the new -csv option, which automatically writes out a "SourceFile" column which is the full path name of the file:

exiftool -gpslatitude -gpslongitude -csv -r DIR > out.csv

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: PIBO on November 29, 2011, 12:07:09 PM
Wow! Always such fast and clear responses. Thanks so much.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: BenjaminTheThird on March 02, 2017, 10:29:04 PM
Hi Phil,
I'm having troubles with the command to extract the GPS data. It doesn't write the .txt file. Any ideas?
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Hayo Baan on March 03, 2017, 01:13:21 AM
What system are you running on, and what is the exact command you used?
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on March 03, 2017, 07:19:05 AM
If you used the command in my first post of this thread, it will have created an "out.txt" file in the current directory from where you ran exiftool.

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: BenjaminTheThird on March 03, 2017, 07:44:16 AM
Thank you both for your responses. Yes it's there alright...up a couple of directories. I kept expecting to see it in the same directory as the photos (my programmer Neighbour helped me straight away). Apologies if I wasted your time. I can see I'm going to be having fun with ExifTool...I've been able to create a photo (Google) map of over 100 images of road defects (on proof sheets). I've got 1000's more to do - so your tool is awesome for the job [just importing a photo library into Google Maps muddled up the sequence for some reason]. I just donated $10AUD. Much obliged, Ben.  :)
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on March 03, 2017, 09:06:26 AM
Hi Ben,

Glad you got it working.

Thanks for the donation!

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: pgogborn on March 19, 2017, 11:54:31 AM
This thread gave me a quick solution to what I wanted to do in particular and gave me a toehold into understanding/using the power of ExifTool.

Thank you Phil Harvey.

Title: Re: Extract GPS coordinates for all pictures in one file
Post by: wallfatt on April 10, 2017, 10:11:12 AM
Quote from: BenjaminTheThird on March 02, 2017, 10:29:04 PM
Hi Phil,
I'm having troubles with the command to extract the GPS data. It doesn't write the .txt file. Any ideas?


Hi all.
Im having the same issue. When i try:
exiftool -filename -directory -gpslatitude -gpslongitude -T -r DIR > out.txt

my txt is created, but its blank, despite i see a command line being create with all data that i wish (and closes after).
Im using windows 7.

Thanks for help.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on April 10, 2017, 10:39:22 AM
If you are typing this command in a cmd.exe window then I don't see why it shouldn't work.

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: wallfatt on April 10, 2017, 10:56:11 AM
Quote from: Phil Harvey on April 10, 2017, 10:39:22 AM
If you are typing this command in a cmd.exe window then I don't see why it shouldn't work.

- Phil

Its on a cmd.exe window.

when i try simple "echo" command on a string to write on a txt, its works.
but exiftool data its not recorded on a txt when a use code above.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on April 10, 2017, 10:58:49 AM
I don't understand it, but you can work around the problem by having ExifTool write the output text file with this command:

exiftool -filename -directory -gpslatitude -gpslongitude -T -r -W+! out.txt DIR

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: wallfatt on April 10, 2017, 11:04:41 AM
Still not working with this code.
When i run exiftool, a new cmd window is opened?
Maybe its the problem...
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on April 10, 2017, 11:26:55 AM
The steps are:

1. Run "cmd.exe"

2. Type your exiftool command in the cmd.exe window

If you do this, then a new cmd window should not open.  (or at least I don't understand why it would.  If it does, then something funny is going on)

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: wallfatt on April 10, 2017, 11:48:01 AM
Im doind exactly it, Phil.
And its opening a new cmd window. When this new cmd windows finishes, it closes fast and return to old cmd window (i can see command, but no results).

My exiftool.exe is in C:Windows folder

Trying to search now how to not open a new cmd window.
thanks anyway
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: wallfatt on April 10, 2017, 12:06:58 PM
problem solved.

i reduced windows defender level privileges and it worked.
thanks
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on April 10, 2017, 02:20:16 PM
Wow.  I would not have guessed that Windows Defender would cause another cmd.exe window to open.  That's just crazy.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: melkhafif on June 14, 2017, 11:31:37 AM
Hi Phil,
I followed your posts, thank you for all your help! I tried to export long/lat coordinates in decimal and the time from a bunch of geotagged images and am running into problems.
I am working on a Mac. Here is the code I am using:

exiftool -filename -gpslatitude -gpslongitude -time -T –n  DIR > out.csv

I am receiving an error..."n" is not found and is "time" not found.

Any Advice? I tried it yesterday with the simple code [without n and time] and it worked.

Best, Mona
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on June 14, 2017, 11:39:11 AM
Hi Mona,

What time are you trying to export?  GPSTimeStamp (and maybe GPSDateStamp too?) I assume.  And your -n problem is because the dash is not a minus character, but instead is some sort of unicode dash.

Try this:

exiftool -filename -gpslatitude -gpslongitude -gpstimestamp -gpsdatestamp -n DIR > out.csv

- Phil
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Rizki_633469 on July 12, 2017, 01:16:49 PM
Hii Phil,
I want to ask, how to insert long,lat,alt, to images using exiftool?

i have problem to insert coordinate to my images?

Thank you,
Rizki
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: StarGeek on July 12, 2017, 02:02:40 PM
Under Windows, it's easier to write GPS coordinates if you have them in decimal format e.g. 40.6892, -74.0445.  Additionally, there is a reference tag for each value of Altitude, Latitude, and Longitude to account for whether the value is above/below sea level, North/South, or East/West.  So in the case of the above value, you could write:
exiftool -GPSLatitude=40.6892 -GPSLatitudeRef=N -GPSLongitude=-74.0445  -GPSLongitudeRef=W -GPSAltitude=10 -GPSAltitudeRef=Above

Exiftool is smart enough that you can just assign the GPS value to the associated reference tag and it will figure out the correct value (though you'll need a +/- for the GPSAltitudeRef):
exiftool -GPSLatitude=40.6892 -GPSLatitudeRef=40.6892 -GPSLongitude=-74.0445  -GPSLongitudeRef=74.0445 -GPSAltitude=10 -GPSAltitudeRef=+10

See GPS Tags (http://www.exiftool.org/TagNames/GPS.html) for some further information.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: StarGeek on July 13, 2017, 04:55:37 PM
Quote from: StarGeek on July 12, 2017, 02:02:40 PMUnder Windows, it's easier to write GPS coordinates if you have them in decimal format

Replying to myself.  The problem I always had was trying to escape the double quotes for the seconds with DMS coordinates.  After re-reading the link I provided, I finally noticed that exiftool doesn't need those extra bits.  It will happily accept the DMS without them.  So -GPSLatitude="‎40 41 21.2892 N" -GPSLatitudeRef="‎40 41 21.2892 N" works perfectly well.  Today I learned.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Rizki_633469 on July 15, 2017, 02:38:56 AM
Thank you Star,

How about to inject coordinate using .csv file? i have problem when i do that.

Thank you for advice,
Rizki,
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: StarGeek on July 15, 2017, 04:32:51 PM
Each line of your CSV is enclosed in quotes.  That means each line is a single cell.  Remove the leading and trailing quote and it should work.
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Kirubel Tadesse on March 15, 2018, 01:49:59 PM
Hello everyone,

I was using the command [exiftool -filename -gpslatitude -gpslongitude -T U1 > out.txt]. When I open the out.txt file I get the names of the image and - - (two dashes). Does that me the images doesn't content GPS fields? I also would like to know which time is the image created time among (Modification, Access, Inode Date/TIme)?
Title: Re: Extract GPS coordinates for all pictures in one file
Post by: Phil Harvey on March 15, 2018, 01:55:00 PM
Yes, a dash means the given tag wasn't extracted from the file.

Add -createdate to your command to extract the creation time if it exists in the metadata.

As for filesystem creation date: If you are on Unix the file creation date isn't stored in the filesystem.  On Mac, this can be accessed through the MDItemFSCreationDate tag.

- Phil