From 3eb17f53b58ac54ecad7f37b0d6f5a4646fc3f16 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 6 Mar 2020 14:36:02 +0100 Subject: [PATCH] First baby steps towards GPX handling - mainly foolish test output. --- CHANGELOG.md | 2 +- Readme.md | 3 ++- exif_rad.py | 32 +++++++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd1396..533955e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - +- Added GPX parser ## [0.2] - 2020-02-05 ### Added diff --git a/Readme.md b/Readme.md index 6b62b86..bb745fd 100644 --- a/Readme.md +++ b/Readme.md @@ -11,9 +11,10 @@ It then creates a `UserComment` Exif tag with the actual measured radiation at t ## Dependencies Right now it depends on the following non-core Python 3 libraries: - * [py3exiv2](https://pypi.org/project/py3exiv2/) A Python 3 binding to the library exiv2. + * [py3exiv2](https://pypi.org/project/py3exiv2/) A Python 3 binding for (lib)exiv2. * [boost.python3](http://www.boost.org/libs/python/doc/index.html) Welcome to Boost.Python, a C++ library which enables seamless interoperability between C++ and the Python programming language. * [exiv2](http://www.exiv2.org/) Exiv2 is a Cross-platform C++ library and a command line utility to manage image metadata. + * [gpxpy](https://github.com/tkrajina/gpxpy) gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks. ## Requirements * GeigerCounter log file in csv format as it is being exported by the software GeigerLog. diff --git a/exif_rad.py b/exif_rad.py index 7ad52ad..9f661c6 100755 --- a/exif_rad.py +++ b/exif_rad.py @@ -12,6 +12,7 @@ import shutil import csv import argparse import pyexiv2 +import gpxpy # SIFACTOR for GQ Geiger counters @@ -24,17 +25,19 @@ import pyexiv2 # Configure argument parser for cli options parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, - description='''A tool that writes - radiation levels (and optionally geocoordinates) to image files - and extracts the infos from external sources.''') + description='''A unix-tyle tool that + extracts GPS and/or radiation data from GPX/CSV files and writes + them into the Exif tags of given photos.''') parser.add_argument('-si', '--sifactor', type=float, default=0.0065, help='Factor to multiply recorded CPM with.') parser.add_argument('csv', metavar='CSV', type=str, help='Geiger counter history file in CSV format.') +parser.add_argument('-g', '--gpx', metavar='GPX', type=str, + help='GPS track in GPX format') parser.add_argument('photos', metavar='Photo', type=str, nargs='+', help='One or multiple photo image files to process.') parser.add_argument('-o', '--outdir', type=str, default='.', - help='Directory to output processed photos') + help='Directory to output processed photos.') args = parser.parse_args() @@ -72,7 +75,6 @@ for srcphoto in args.photos: csvreader = csv.reader(filter(lambda row: row[0] != '#', f), delimiter=',', skipinitialspace=True) - print('Processing file:', photo_basename, end='\r') for _, csvrawtime, csvrawcpm, _ in csvreader: csvtime = datetime.fromisoformat(csvrawtime) # Process image if its timestamp is found in CSV log (compares 2 datetime objects) @@ -93,3 +95,23 @@ for srcphoto in args.photos: print('{:<15} {:<20} {:<22}'.format(photo_basename, str(pictime), 'NOT FOUND!')) # close CSV file f.close() + + # Import GPX track(s) + if hasattr(args, 'gpx'): + gpx_file = open(args.gpx, 'r') + gpxreader = gpxpy.parse(gpx_file) + + for waypoint in gpxreader.waypoints: + for track in gpxreader.tracks: + for segment in track.segments: + for point in segment.points: + #if pictime == point.time: + print(type(point.time)) + print(type(pictime)) + print(pictime, 'vs.', point.time) +# print('Point at ({0},{1}) -> {2}'.format(point.latitude, point.longitude, point.time)) + +''' + 2018-08-04 17:50:16 vs. 2018-08-04 17:50:03.535000+00:00 + + 2018-08-04 17:50:16 vs. 2018-08-04 17:50:23.327000+00:00'''