Total Complexity | 6 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 94.74% |
Changes | 0 |
1 | """utils.parse. |
||
2 | --- |
||
3 | Parse needed to make exifread dictionaries easier |
||
4 | """ |
||
5 | |||
6 | |||
7 | 1 | def gps_parse(tags: dict) -> dict: |
|
8 | """Returns GPS degrees.""" |
||
9 | 1 | latitude = tags["GPS GPSLatitude"] |
|
10 | 1 | latitude_ref = tags["GPS GPSLatitudeRef"] |
|
11 | 1 | longitude = tags["GPS GPSLongitude"] |
|
12 | 1 | longitude_ref = tags["GPS GPSLongitudeRef"] |
|
13 | 1 | if latitude: |
|
14 | 1 | lat_value = _convert_to_degrees(latitude) |
|
15 | 1 | if latitude_ref.values != "N": |
|
16 | lat_value = -lat_value |
||
17 | 1 | if longitude: |
|
18 | 1 | lon_value = _convert_to_degrees(longitude) |
|
19 | 1 | if longitude_ref.values != "E": |
|
20 | 1 | lon_value = -lon_value |
|
21 | 1 | return {"latitude": lat_value, "longitude": lon_value} |
|
22 | |||
23 | |||
24 | 1 | def _convert_to_degrees(value) -> float: |
|
25 | """Degrees converter function. |
||
26 | Helper function to convert the GPS coordinates stored in the EXIF to degrees in float format |
||
27 | :param value: |
||
28 | :type value: exifread.utils.Ratio |
||
29 | """ |
||
30 | 1 | d = float(value.values[0].num) / float(value.values[0].den) |
|
31 | 1 | m = float(value.values[1].num) / float(value.values[1].den) |
|
32 | 1 | s = float(value.values[2].num) / float(value.values[2].den) |
|
33 | |||
34 | return d + (m / 60.0) + (s / 3600.0) |
||
35 |