Added function which converts decimal position value to WGS-84 notation.

This commit is contained in:
Marcus Scholz 2020-03-12 20:35:49 +01:00
parent f07eb0c691
commit cafda4cf35
2 changed files with 43 additions and 13 deletions

View File

@ -7,6 +7,7 @@ from datetime import datetime
import os
import shutil
import pyexiv2
import fractions
class Radiation:
''' Handles CSV processing. '''
@ -65,13 +66,39 @@ class Photo:
return pic_aware_time
class Exif:
''' Compiles and writes Exif-Tags from given values. '''
def write_exif(photo, radiation, latitude, longitude, dry_run):
''' Converts, compiles and writes Exif-Tags from given values. '''
def __init__(self, photo, radiation, latitude, longitude, elevation, dry_run):
# self.get_degree = self._to_degree(value, loc)
self.write_exif = self._write_exif(photo, radiation, latitude, longitude, elevation, dry_run)
''' UNTESTED ! '''
# def __repr__(self):
# return 'Photo: %s Creation Date: %s' % (str(self.get_target_photo), str(self.get_date))
def _to_degree(self, value, loc):
if value < 0:
loc_value = loc[0]
elif value > 0:
loc_value = loc[1]
else:
loc_value = ""
abs_value = abs(value)
deg = int(abs_value)
t1 = (abs_value - deg) * 60
minute = int(t1)
second = round((t1 - minute) * 60, 5)
return (deg, minute, second, loc_value)
def _write_exif(self, photo, radiation, latitude, longitude, elevation, dry_run):
metadata = pyexiv2.ImageMetadata(photo)
metadata.read()
lat_deg = self._to_degree(latitude, ["S", "N"])
lng_deg = self._to_degree(longitude, ["W", "E"])
print(lat_deg)
print(lng_deg)
# Set new UserComment
new_comment = 'Radiation ☢ ' + str(radiation) + ' µS/h'
# Exif tags to write
@ -80,12 +107,13 @@ class Exif:
values = [new_comment, latitude, longitude]
# Create metadata object with all data to write
for key, value in zip(keys, values):
#for key, value in zip(keys, values):
# Only create object if there is anything to fill with
if value is not None:
metadata[key] = pyexiv2.ExifTag(key, value)
# if value is not None:
# metadata[key] = pyexiv2.ExifTag(key, value)
# Write Exif tags to file, if not in dry-run mode
if dry_run is not True:
metadata.write()
#if dry_run is not True:
# metadata.write()
return new_comment

View File

@ -11,7 +11,7 @@ import csv
import argparse
import pytz
import gpxpy
from functions import Radiation, Photo
from functions import Radiation, Photo, Exif
# SIFACTOR for GQ Geiger counters
@ -93,12 +93,14 @@ for src_photo in args.photos:
print(photo.get_target_photo, photo.get_date)
# Here the matching magic has to happen
latitude = '51.0234024'
longitude = '7.248347'
latitude = 51.0234024
longitude = 7.248347
radiation = '9001'
elevation = '55'
# Write exif data
#exif_tags = Photo.write_exif(photo.get_target_photo, radiation, latitude, longitude, args.dry)
#print(exif_tags)
exif_tags = Exif(photo.get_target_photo, radiation, latitude, longitude, elevation, args.dry)
print(exif_tags)
# Print table header
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))