Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offset when parsing Exif GPSLatitude/GPSLongitude with QGIS expression #57942

Closed
2 tasks done
boardend opened this issue Jun 30, 2024 · 0 comments · Fixed by #57943
Closed
2 tasks done

Offset when parsing Exif GPSLatitude/GPSLongitude with QGIS expression #57942

boardend opened this issue Jun 30, 2024 · 0 comments · Fixed by #57943
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@boardend
Copy link
Contributor

boardend commented Jun 30, 2024

What is the bug or the crash?

Noticed with an image from a Samsung Galaxy Tab Active 4 Pro (SM-T636B) that the position is slightly off, when using exif/exif_geotag expressions in QGIS.

GPSLatitude/GPSLongitude are stored as rational64u[3], with a rational for degrees, minutes and seconds. If the numerator or denominator of such a rational is bigger then 2^32/2 (2147483648), the int32_t will turn negative and lead to a wrong result while parsing the x/y value to a double in the QgsExifTools.

Note that this only happens with some sensors/images. With most sensors the numerator/denominator will be below the 2^32/2 threshold and the position will be accurate.

Example image (reduced to 1x1 px, but with preserved Exif metadata) can be obtained here: gps_exif_example.zip

Steps to reproduce the issue

  1. Use exif_geotag expression in QGIS to read the position of the gps_exif_example.jpg
    • Bad: 47.766666666663134 / 8.66666666666483 👎
  2. Position the gps_exif_example.jpg with "Import geotagged photos"-Algorithm
    • Good 47.781829000012785 / 8.674557000032523 👍
    • This uses the Exif parser of GDAL
  3. Compare the two positions obtained by QGIS:

Screenshot from 2024-06-30 13-46-26

Versions

Tested with 3.34.8 and latest master (6246369) with Exiv2 0.27.5

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

GPSLatitude/GPSLongitude parsing of gps_exif_example.jpg

  • QGIS will parse the GPSLatitude (Exiv2::Value) rationals with int32_t as: 47/1 deg., 46/1 min., -1/78684886 sec.
    • Where sec. should be 4294967295/78684886 with uint32_t
  • QGIS will parse the GPSLongitude (Exiv2::Value) rationals with int32_t as: 8/1 deg., 40/1 min., -1/151203557 sec.
    • Where sec. should be 4294967295/151203557 with uint32_t
Output of exiv2 -Pvkyct gps_exif_example.jpg | grep GPS:
Exif.Image.GPSTag                            Long        1  380  380
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  N  North
Exif.GPSInfo.GPSLatitude                     Rational    3  47/1 46/1 4294967295/78684886  47deg 46' 55"
Exif.GPSInfo.GPSLongitudeRef                 Ascii       2  E  East
Exif.GPSInfo.GPSLongitude                    Rational    3  8/1 40/1 4294967295/151203557  8deg 40' 28"
Exif.GPSInfo.GPSAltitudeRef                  Byte        1  0  Above sea level
Exif.GPSInfo.GPSAltitude                     Rational    1  4294967295/7847670  547.3 m
Exif.GPSInfo.GPSTimeStamp                    Rational    3  8/1 5/1 19/1  08:05:19
Exif.GPSInfo.GPSProcessingMethod             Undefined   3    
Exif.GPSInfo.GPSDateStamp                    Ascii      11  2024:04:19  2024:04:19
Output of exiftool -n -ee '-gps*' gps_exif_example.jpg:
GPS Latitude Ref                : N
GPS Latitude                    : 47.7818290000139
GPS Longitude Ref               : E
GPS Longitude                   : 8.67455700003333
GPS Altitude Ref                : 0
GPS Altitude                    : 547.2920364
GPS Time Stamp                  : 08:05:19
GPS Processing Method           : GPS
GPS Date Stamp                  : 2024:04:19
GPS Altitude                    : 547.2920364
GPS Date/Time                   : 2024:04:19 08:05:19Z
GPS Latitude                    : 47.7818290000139
GPS Longitude                   : 8.67455700003333
GPS Position                    : 47.7818290000139 8.67455700003333
@boardend boardend added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jun 30, 2024
boardend added a commit to boardend/QGIS that referenced this issue Jun 30, 2024
boardend added a commit to boardend/QGIS that referenced this issue Jun 30, 2024
qgis-bot pushed a commit that referenced this issue Jul 3, 2024
qgis-bot pushed a commit that referenced this issue Jul 3, 2024
nyalldawson pushed a commit that referenced this issue Jul 3, 2024
nyalldawson pushed a commit that referenced this issue Jul 3, 2024
elpaso pushed a commit to elpaso/QGIS that referenced this issue Jul 11, 2024
nyalldawson pushed a commit that referenced this issue Jul 19, 2024
nyalldawson pushed a commit that referenced this issue Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
1 participant