ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: aeciolemos on March 15, 2025, 06:47:07 AM

Title: Command line to sort files based on GPS Altitude
Post by: aeciolemos on March 15, 2025, 06:47:07 AM
Hi,
This is my first post! I just downloaded exiftool and it is amazing. I have an issue with some 30,000 photos where I accidentally mixed them up. I have 2 drone mapping scenarios, with different altitudes. I need to find the photos done at 60m and the ones done at 120m and put them in separate folders.

I assume exiftool can do that based on other topics, but I need a little help on how to do this on Windows. I just downloaded the latest version, so any help is appreciated.

Thanks
Title: Re: Command line to sort files based on GPS Altitude
Post by: greybeard on March 15, 2025, 08:06:05 AM
Having just looked at a drone photo I see absolute and relative altitudes.

You can use this command to see all the tags with "Alt" in their names:

exiftool -s "-*Alt*"  <filename>

Sample output:

GPSAltitudeRef                  : Above Sea Level
AbsoluteAltitude                : 341.345
RelativeAltitude                : +90.096
GPSAltitude                     : 341 m Above Sea Level

The altitudes also seem to have three decimal places so I assume you want to round down to 60m or 120m

The command would be (for the current directory) :

exiftool -if "$AbsoluteAltitude=~/\+60\./" "-Directory=dir" .

if you want to use an altitude range then it would be something like

exiftool -if "$AbsoluteAltitude > 60 and $AbsoluteAltitude < 61" "-Directory=dir" .

Caveat : I tried this using a Mac where the syntax may be slightly different - test carefully before you run it on your 30,000 photos
Title: Re: Command line to sort files based on GPS Altitude
Post by: StarGeek on March 15, 2025, 11:19:15 AM
Make sure and use CMD, not PowerShell, as PSs quoting rules are different from every other command line.

Your conditions are a little vague. Do you mean images with an exact altitude of 60 and 120? Or do you mean something like
0-60
61-120
120+

If your files don't have an AbsoluteAltitude tag, then you can use GPSAltitude, but you would want to add a hashtag to the end of it, e.g. GPSAltitude#. This allows comparing the raw number without the extra text (though it might still work either way, Perl is flexible about this IIRC).
Title: Re: Command line to sort files based on GPS Altitude
Post by: aeciolemos on March 15, 2025, 04:09:31 PM
Hi @greybeard
Thank you for the quick replies! This tool is awesome.

I ran the command on a few photo and I got strangely different results:

GPSAltitudeRef                  : Above Sea Level
AltitudeType                    : GpsFusionAlt
AbsoluteAltitude                : +83.568
RelativeAltitude                : +249.900
GPSAltitude                     : 83.5 m Above Sea Level

GPSAltitudeRef                  : Above Sea Level
AltitudeType                    : GpsFusionAlt
AbsoluteAltitude                : +176.981
RelativeAltitude                : +200.000
GPSAltitude                     : 176.9 m Above Sea Level

GPSAltitudeRef                  : Above Sea Level
AltitudeType                    : GpsFusionAlt
AbsoluteAltitude                : +176.981
RelativeAltitude                : +200.000
GPSAltitude                     : 176.9 m Above Sea Level

GPSAltitudeRef                  : Below Sea Level
AltitudeType                    : GpsFusionAlt
AbsoluteAltitude                : -14.568
RelativeAltitude                : +59.900
GPSAltitude                     : 14.5 m Below Sea Level


I think the RelativeAltitude would be the best bet. I don't understand why the drone would think I am below sea level, but ok.

The first ones I was indeed at 200m and the last one I was at 60m (59.9 is close enough).

I think I would need to put a range of 50-70 and then 190-210, for example, to separate the two main types. I ran two sets of flights at 60m and 200m (not 120m as I had said before, my mistake).

So I ran this:
exiftool -if "$AbsoluteAltitude > 50 and $AbsoluteAltitude < 70" "-Directory=dir" .

and it failed with this:
    1 directories scanned
  642 files failed condition
    0 image files read

Then I ran
exiftool -if "$RelativeAltitude > 50 and $RelativeAltitude < 70" "-Directory=dir" .
and got:

    1 directories scanned
    1 files failed condition
  643 image files updated

So it managed to sort 642 of 643, which is what I expected from the sample, so it worked!

Lastly, I ran
Exiftool\exiftool -if "$RelativeAltitude > 120 " "-Directory=dir2" .
    1 directories scanned
    1 directories created
    1 image files updated
and it sorted the last image, which was above 120m

Thank you! This is amazing!
Title: Re: Command line to sort files based on GPS Altitude
Post by: aeciolemos on March 15, 2025, 04:13:32 PM
Quote from: StarGeek on March 15, 2025, 11:19:15 AMMake sure and use CMD, not PowerShell, as PSs quoting rules are different from every other command line.

Your conditions are a little vague. Do you mean images with an exact altitude of 60 and 120? Or do you mean something like
0-60
61-120
120+

If your files don't have an AbsoluteAltitude tag, then you can use GPSAltitude, but you would want to add a hashtag to the end of it, e.g. GPSAltitude#. This allows comparing the raw number without the extra text (though it might still work either way, Perl is flexible about this IIRC).

Thank you so much for your input! Yes, I use CMD - I though Powershell would not be the best for this.

What I meant is I have photos taken at 60m (so let's say 55 to 65m, but the drone should always be at 60m above take-off). I have another set that was taken at 200m (let's say 195 to 205m) and I mixed them up accidentally. Now I need to sort them into two folders, for they are different sets of data.

QuoteIf your files don't have an AbsoluteAltitude tag, then you can use GPSAltitude, but you would want to add a hashtag to the end of it, e.g. GPSAltitude#. This allows comparing the raw number without the extra text (though it might still work either way, Perl is flexible about this IIRC).

Yes, I love Perl! It worked great with RelativeAltitude. I am still puzzled by some of the results for the GPS data - especially that one that says BELOW SEA LEVEL!

Thanks again!
Title: Re: Command line to sort files based on GPS Altitude
Post by: StarGeek on March 15, 2025, 04:46:23 PM
Quote from: aeciolemos on March 15, 2025, 04:13:32 PMI am still puzzled by some of the results for the GPS data - especially that one that says BELOW SEA LEVEL!

What are the GPS coordinates for that file? Though it could have been a glitch.