mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 22:37:05 +00:00
now outputs lat+lon onto /l/*.html page for a photo with GPS exif
This commit is contained in:
@@ -126,7 +126,7 @@ def extract_gps(dict):
|
||||
def is_present(gpsifd):
|
||||
item = getattr(piexif.GPSIFD, gpsifd)
|
||||
if item in dict:
|
||||
print(f" {gpsifd} = {item}")
|
||||
print(f" {gpsifd} = id '{item}'")
|
||||
return dict[item]
|
||||
return None
|
||||
|
||||
@@ -139,6 +139,13 @@ def extract_gps(dict):
|
||||
def rational(tup):
|
||||
nom, denom = tup
|
||||
return nom/denom
|
||||
|
||||
def rationalise(item):
|
||||
df, mf, sf = item
|
||||
d = rational(df)
|
||||
m = rational(mf)
|
||||
s = rational(sf)
|
||||
return (d, m, s)
|
||||
|
||||
compass_points = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"]
|
||||
if bearing := extract("GPSImgDirection"):
|
||||
@@ -168,26 +175,54 @@ def extract_gps(dict):
|
||||
ds = ds.decode()
|
||||
else:
|
||||
ds = ""
|
||||
|
||||
|
||||
if item := is_present("GPSTimeStamp"):
|
||||
hf, mf, sf = item
|
||||
h = rational(hf)
|
||||
m = rational(mf)
|
||||
s = rational(sf)
|
||||
h, m, s = rationalise(item)
|
||||
timestamp_utc = f"{ds} {h:02.0f}:{m:02.0f}:{s:02.0f} +00:00 UTC"
|
||||
else:
|
||||
timestamp_utc = f"{ds}"
|
||||
|
||||
|
||||
|
||||
print(f"attempting latitude")
|
||||
if ref := is_present("GPSLatitudeRef"):
|
||||
latref = ref.decode()
|
||||
else:
|
||||
latref = ""
|
||||
|
||||
if item := is_present("GPSLatitude"):
|
||||
d, m, s = rationalise(item)
|
||||
latitude = f"{d:02.0f}:{m:02.0f}:{s:02.0f} {latref}"
|
||||
print(f"{latitude=}")
|
||||
latitude = dms2dd(d, m, s, latref)
|
||||
print(f"{latitude=}")
|
||||
else:
|
||||
print("failed to find latitude")
|
||||
|
||||
print(f"attempting logitude")
|
||||
if ref := is_present("GPSLongitudeRef"):
|
||||
lonref = ref.decode()
|
||||
else:
|
||||
lonref = ""
|
||||
|
||||
if item := is_present("GPSLongitude"):
|
||||
d, m, s = rationalise(item)
|
||||
longitude = f"{d:02.0f}:{m:02.0f}:{s:02.0f} {lonref}"
|
||||
print(f"{longitude=}")
|
||||
longitude = dms2dd(d, m, s, lonref)
|
||||
print(f"{longitude=}")
|
||||
else:
|
||||
print("failed to find latitude")
|
||||
|
||||
location = f"{latitude:08.5f} {latref}, {longitude:09.5f} {lonref}"
|
||||
print(direction)
|
||||
print(altitude)
|
||||
print(timestamp_utc)
|
||||
# location = dms2dd() # to do...
|
||||
print(location)
|
||||
|
||||
return f"{direction}<br />{altitude}</br />{timestamp_utc}<br />"
|
||||
return f"{direction}<br />{location}<br />{altitude}</br />{timestamp_utc}<br />"
|
||||
|
||||
def fix_dump_bugs(exif_dict):
|
||||
"""piexif has a bug, this gets around it.
|
||||
"""piexif has several bugs, this gets around it.
|
||||
The Exif standard leaves some instance types "undefined". Great :-(
|
||||
|
||||
see https://github.com/hMatoba/Piexif/issues/83
|
||||
@@ -204,12 +239,12 @@ def fix_dump_bugs(exif_dict):
|
||||
if isinstance(cc, tuple):
|
||||
print(f"PIEXIF BUG workaround: 37121 {cc} is {type(cc)}")
|
||||
exif_dict['Exif'][37121] = ",".join([str(v) for v in cc]).encode("ASCII")
|
||||
if 37380 in exif_dict['Exif']:
|
||||
# exposure bias
|
||||
cc = exif_dict['Exif'][37380]
|
||||
if isinstance(cc, tuple):
|
||||
print(f"PIEXIF BUG workaround: 37380 {cc} is {type(cc)}")
|
||||
exif_dict['Exif'][37380] = (0, 1)
|
||||
# if 37380 in exif_dict['Exif']:
|
||||
# # exposure bias
|
||||
# cc = exif_dict['Exif'][37380]
|
||||
# if isinstance(cc, tuple):
|
||||
# print(f"PIEXIF BUG workaround: 37380 exposure bias: {cc} is {type(cc)}")
|
||||
# exif_dict['Exif'][37380] = (0, 1)
|
||||
|
||||
if 50728 in exif_dict['Exif']:
|
||||
cc = exif_dict['Exif'][50728]
|
||||
|
||||
Reference in New Issue
Block a user