mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-18 19:07:10 +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):
|
def is_present(gpsifd):
|
||||||
item = getattr(piexif.GPSIFD, gpsifd)
|
item = getattr(piexif.GPSIFD, gpsifd)
|
||||||
if item in dict:
|
if item in dict:
|
||||||
print(f" {gpsifd} = {item}")
|
print(f" {gpsifd} = id '{item}'")
|
||||||
return dict[item]
|
return dict[item]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -140,6 +140,13 @@ def extract_gps(dict):
|
|||||||
nom, denom = tup
|
nom, denom = tup
|
||||||
return nom/denom
|
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"]
|
compass_points = ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"]
|
||||||
if bearing := extract("GPSImgDirection"):
|
if bearing := extract("GPSImgDirection"):
|
||||||
compass_lookup = round(bearing / 45)
|
compass_lookup = round(bearing / 45)
|
||||||
@@ -170,24 +177,52 @@ def extract_gps(dict):
|
|||||||
ds = ""
|
ds = ""
|
||||||
|
|
||||||
if item := is_present("GPSTimeStamp"):
|
if item := is_present("GPSTimeStamp"):
|
||||||
hf, mf, sf = item
|
h, m, s = rationalise(item)
|
||||||
h = rational(hf)
|
|
||||||
m = rational(mf)
|
|
||||||
s = rational(sf)
|
|
||||||
timestamp_utc = f"{ds} {h:02.0f}:{m:02.0f}:{s:02.0f} +00:00 UTC"
|
timestamp_utc = f"{ds} {h:02.0f}:{m:02.0f}:{s:02.0f} +00:00 UTC"
|
||||||
else:
|
else:
|
||||||
timestamp_utc = f"{ds}"
|
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(direction)
|
||||||
print(altitude)
|
print(altitude)
|
||||||
print(timestamp_utc)
|
print(timestamp_utc)
|
||||||
# location = dms2dd() # to do...
|
# 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):
|
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 :-(
|
The Exif standard leaves some instance types "undefined". Great :-(
|
||||||
|
|
||||||
see https://github.com/hMatoba/Piexif/issues/83
|
see https://github.com/hMatoba/Piexif/issues/83
|
||||||
@@ -204,12 +239,12 @@ def fix_dump_bugs(exif_dict):
|
|||||||
if isinstance(cc, tuple):
|
if isinstance(cc, tuple):
|
||||||
print(f"PIEXIF BUG workaround: 37121 {cc} is {type(cc)}")
|
print(f"PIEXIF BUG workaround: 37121 {cc} is {type(cc)}")
|
||||||
exif_dict['Exif'][37121] = ",".join([str(v) for v in cc]).encode("ASCII")
|
exif_dict['Exif'][37121] = ",".join([str(v) for v in cc]).encode("ASCII")
|
||||||
if 37380 in exif_dict['Exif']:
|
# if 37380 in exif_dict['Exif']:
|
||||||
# exposure bias
|
# # exposure bias
|
||||||
cc = exif_dict['Exif'][37380]
|
# cc = exif_dict['Exif'][37380]
|
||||||
if isinstance(cc, tuple):
|
# if isinstance(cc, tuple):
|
||||||
print(f"PIEXIF BUG workaround: 37380 {cc} is {type(cc)}")
|
# print(f"PIEXIF BUG workaround: 37380 exposure bias: {cc} is {type(cc)}")
|
||||||
exif_dict['Exif'][37380] = (0, 1)
|
# exif_dict['Exif'][37380] = (0, 1)
|
||||||
|
|
||||||
if 50728 in exif_dict['Exif']:
|
if 50728 in exif_dict['Exif']:
|
||||||
cc = exif_dict['Exif'][50728]
|
cc = exif_dict['Exif'][50728]
|
||||||
|
|||||||
Reference in New Issue
Block a user