First baby steps towards GPX handling - mainly foolish test output.

This commit is contained in:
Marcus Scholz 2020-03-06 14:36:02 +01:00
parent 04fad8d5b8
commit 3eb17f53b5
3 changed files with 30 additions and 7 deletions

View File

@ -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

View File

@ -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.

View File

@ -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))
'''<class 'datetime.datetime'>
2018-08-04 17:50:16 vs. 2018-08-04 17:50:03.535000+00:00
<class 'datetime.datetime'>
2018-08-04 17:50:16 vs. 2018-08-04 17:50:23.327000+00:00'''