Skip to content

attempt to fix #149 wrong coordinates in EXIF info

Daniel Frost requested to merge Danfro/camera-app:fixcoord into main

Summary: This MR attempts to fix #149 by rewriting the coordinates to the EXIF info of an image with stripped decimals of the coordinates seconds.

A Context and explanations

I did investigate and as far as I could find out, the reason is this:

  • in ViewFinderOverlay.qml the current GPS coordinate gets assigned to the Camera object
  • the values are double/float numbers
  • this adds the coordinates to the camera's metadata, that is of type Double for GPS Altitude and Longitude
  • they end up in Exif.GPSInfo.GPSAltitude and Exif.GPSInfo.GPSLongitude (https://exiv2.org/tags.html)
  • EXIF standard defines GPS coordinates as so called rationals. That is a string with numbers and precision parameters
  • the string would be in a format such as dd/1,mm/1,ss/1 with dd=degree, mm=minutes, ss=seconds and "/1" being the precision, with "/1"=no decimals, "/100" two decimals or "/10000" four decimals

Earth Circumference is about 40.000 km Wikipedia. 40.000.000 m divided by 360° by 60' by 60" results in 1" being equal to about 31m. So using seconds without decimals results in photo coordinates being restricted to an accuracy of about 31m. Using 1 decimal second would lower that to about 3m, using two decimals to below 1m.

Although a single GPS position is not below 1m accuracy, it certainly can be in good conditions better than 31m. So specifying 1 decimal would be preferable, two would make sure all the accuracy that is available will be used.

Sadly that seems not to be an option for us. 😢 Some internal Qt functionality does add the data from the images metadata to the images EXIF data. (At least I could not find an explicit action for that in camera apps code.) Here is where the problems start. The writing to EXIF data does only allow seconds without any decimals. Format dd/1,mm/1,ss/1 will work, dd/1,mm/1,ss/100 will not work. This results in a coordinate with seconds value much more than 60", for instance 12° 34' 5678". Obviously seconds should never exceed 60.

B Description of solution

This MR now adds two things:

  1. a function to convert decimal degree to sexadecimal degree to ViewFinderOverlay.qml
  2. a GPS to EXIF writer function to fileoperations.cpp

The logic is as follows: After an image has been saved to disk (onImageSaved event) and has got the broken GPS EXIF info, the coordinates are overwritten in the EXIF infos with the correct values with seconds stripped by all decimals. Thus the coordinate is correct with the limits of the accuracy of about 31m.

Note: I tried writing the coordinate to EXIF with decimals but failed. Although in theory it should be possible (and does make sense for accuracy) as

  • the Cookbook examples here gives seconds with decimals
  • the EXIF specification does allow the format to specify the number of decimals used

Since the examples are python and R, maybe (wild guess) only when using c++ this limitation applies?

Merge request reports