Search code examples
gpsmetadataexiftool

How to delete GPS metadata only if it's match a coordinate using ExifTool?


I want to delete all GPS information of my photos only if it match a specific GPS coordinate.

I have read the man page but I'm not sure that's possible.


Solution

  • To match an exact coordinate, something like this (windows version):
    exiftool -if "$GPSLongitude eq '‎74 deg 2\' 40.20\" W' and $GPSLatitude eq '40 deg 41\' 21.28\" N'" -gps*= FileOrDir

    or if you're using numeric coordinates
    exiftool -if "$GPSLongitude# == -74.0445 and $GPSLatitude# == 40.6892444444444" -gps*= FileOrDir

    I used -gps*= to clear out all tags that start with gps because it's possible that there could be a lot more tags as well as XMP gps tags. If you want to just clear out position data while leaving GPS direction/speed/timestamp/destination/etc data, then you could use -GPSLatitude= -GPSLongitude= -GPSLatitudeRef= -GPSLongitudeRef= instead (maybe -GPSAltitude= -GPSAltitudeRef= as well).

    For the first command in Windows, you'll have to escape the single and double quotes that are inside the single quoted part of the equation with backslashes. I'm not sure how it would be done on Mac/Linux.

    The one main problem would be the degree of accuracy. If you have a number is close, but not exactly equal to the gps local stored in the file, you won't get a match. At that point, you may want to look into the -c option where you can specify the degree of precision.
    exiftool -if "$GPSLongitude == -74.0445 and $GPSLatitude == 40.689244" -c "%+.6f" -gps*= FileOrDir

    Finally, if you want to get more complex, you can put just about any perl expression as the argument for the -if option. For example, you could subtract your number from the $GPSLatitude and get the absolute value to get a range to compare. Example from the Exiftool forums:
    exiftool -if 'abs($gpslatitude# - 52.3728268506806) < 1e-3 and abs($gpslongitude# - 4.89373108651944) < 1e-3'