Add GPS from JSON ONLY if there is valid GPS data

Started by publicENEMY, August 13, 2023, 09:20:20 AM

Previous topic - Next topic

publicENEMY

I am fixing my Google Takeout data. There are GPS data stored in json files for each of the image/video files.
Some of the files has 0 GPS data while some has meaningful GPS data.

Example 0 GPS data
  "geoData": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },
  "geoDataExif": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },

Example meaningful GPS data
  "geoData": {
    "latitude": 2.8900221999999998,
    "longitude": 101.6788333,
    "altitude": 26.26916221033868,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },
  "geoDataExif": {
    "latitude": 2.8900221999999998,
    "longitude": 101.6788333,
    "altitude": 26.26916221033868,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },

I use this command (stored in merge.args.) to import GPS data from json to image/video files. To use the command I run exiftool -@ merge.args Dir

# Reference https://github.com/kaytat/exiftool-scripts-for-takeout
# Fill in from Google's JSON

# Look at all media files and ignore JSON
--ext
json

# Recursive
-r

# Check if the corresponding JSON exists
-if
(-e "${Directory}/${Filename}".".json")

# Attempt to read in the JSON
-tagsfromfile
%d%F.json

#
# Write out the tags. Use ConvertUnixTime to try and convert the UTC timestamp
# to a reasonable local EXIF string.
#

# EXIF for regular JPG photos
-AllDates<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,1)}

# PNG-specific
-XMP-Exif:DateTimeOriginal<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,1)}
-PNG:CreationTime<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,1)}

# Quicktime / MP4. Assume that timestamp is in UTC.
-QuickTime:TrackCreateDate<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,0)}
-QuickTime:TrackModifyDate<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,0)}
-QuickTime:MediaCreateDate<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,0)}
-QuickTime:MediaModifyDate<${PhotoTakenTimeTimestamp;$_=ConvertUnixTime($_,0)}

#GPS
-GPSAltitude*<GeoDataAltitude
-GPSLatitude*<GeoDataLatitude
-GPSLongitude*<GeoDataLongitude

-progress

The command will import all GPS coordinates from json files including the one that have 0 value.

How do I import GPS coordinates from json files ONLY if there is meaningful GPS coordinates?

Thanks.

wywh

Yes, such .json files have dummy zero data, and all such images erroneously get a wrong GPS in the Atlantic.

This trick from StarGeek ignores any such 0.0 latitude and longitude in .json.:

'-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}' '-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}'
https://exiftool.org/forum/index.php?topic=12905.msg69771#msg69771

- Matti

publicENEMY

Found the solution. Change the GPS thing into
-GPSAltitude*<${GeoDataAltitude;$_ = undef if $_ eq "0.0"}
-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}
-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}

While it works, it does gives lots of warnings.