14 Commits
v1.0 ... v1.1.2

Author SHA1 Message Date
34f5ce14bc hot fixes for moving package into main() 2026-02-08 12:47:26 +09:00
d771da77e1 gitignore update 2026-02-08 12:31:33 +09:00
d8cceac003 Remove cache files and uv.lock and add them all to ignore 2026-02-08 12:30:55 +09:00
feda1cf85d Move to uv style project layout
run now with `uv run reverse-geolocate`
2026-02-08 12:29:03 +09:00
65e352e8a4 Merge branch 'master' of github.com:gullevek/reverse_geolocate 2022-11-11 22:36:30 +09:00
38083d8a46 Add .venv folder to gitignore 2022-11-11 22:34:48 +09:00
ce676dea72 Changed indent level for parser arguments
They are all now on the same level indented by one step
2022-11-11 22:32:55 +09:00
8548cc1f0f Add simpe debug print, add 'r' for all regex calls 2022-08-13 15:50:24 +09:00
63202b53f1 add -p for only list unset GPS long/lat entries 2020-10-20 23:59:32 +09:00
2836a40616 Add another City location lookup for google API 2020-10-20 22:33:46 +09:00
19a8c2b997 Fix for [Bug with exempi 2.5.0 #1]
With exempi 2.5.0 when the get_property was called on an unset one, it
crashed with "unkown error".

Fix with checking if property exists before actually getting the
property
2019-04-01 20:58:45 +09:00
217cd87feb Update output info if update is from cache
on write change the output message from only "UPDATED" to also show if
it was read from cache by "UPDATED FROM CACHE"
2018-06-11 23:50:32 +09:00
a0a023859a README update with new fuzzy option info
Also fix footer seperator width
2018-05-18 15:43:48 +09:00
87f8ad4dae Fuzzy cache lookup flow added
Besides the exact GPS coordinate match and optional fuzzy match can be
used via the -d/--fuzzy-cache argument.

The default value is set to to 10m and can be set in the format number
and m/km. Eg 100m, 1km

During the run it calculates the distance from all previous cached
entries and if one falls inside the given fuzzy distance this lookup
data will be used and also stored in the direct GPS cache for further
direct GPS matches
2018-05-18 15:36:08 +09:00
6 changed files with 1498 additions and 1269 deletions

22
.gitignore vendored Normal file
View File

@@ -0,0 +1,22 @@
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv
# Pytest coverate
.coverage
# all .env files
.env
# uv lock files
uv.lock
# composer lock file
composer.lock
vendor/

View File

@@ -4,16 +4,17 @@ Reverse GeoLocate from XMP sidecar files with optional LightRoom DB read
This script will update any of the Country Code, Country, State, City and Location data that is missing in sidecard files. If a Lightroom DB is set, it will read any data from the database and fill in the fields before it tries to get the location name from google with the Latitude and Longitude found in either the XMP sidecar file or the LR database.
#### Installing and setting up
## Installing and setting up
The script uses the following external non defauly python libraries
* xmp toolkit
* requests
install both with the pip3 command
```
pip3 install requests
pip3 install python-xmp-toolkit
```sh
uv sync
```
XMP Toolkit also needs the [Exempi Library](http://libopenraw.freedesktop.org/wiki/Exempi). This one can be install via brew or macports directly.
@@ -21,13 +22,22 @@ See more information for [Python XMP Tool kit](http://python-xmp-toolkit.readthe
## Command line arguments
reverse_geolocate.py [-h] -i
```sh
uv run reverse-geolocate [-h] -i
[XMP SOURCE FOLDER [XMP SOURCE FOLDER ...]]
[-x [EXCLUDE XMP SOURCE FOLDER [EXCLUDE XMP SOURCE FOLDER ...]]]
[-l LIGHTROOM FOLDER] [-s]
[-f <overwrite, location, city, state, country, countrycode>]
[-g GOOGLE API KEY] [-o] [-e EMIL ADDRESS] [-w]
[-r] [-u] [-a] [-c] [-n] [-v] [--debug] [--test]
[-d [FUZZY DISTANCE]] [-g GOOGLE API KEY] [-o]
[-e EMIL ADDRESS] [-w] [-r] [-u] [-a] [-c] [-n]
[-v] [--debug] [--test]
```
or if outside of the project dir
```sh
uv run --project <path to project> reverse-geolocate
```
### Arguments
@@ -38,6 +48,7 @@ Argument | Argument Value | Description
-l, --lightroom | Lightroom DB base folder | The folder where the .lrcat file is located. Optional, if this is set, LR values are read before any Google maps connection is done. Fills the Latitude and Longitude and the location names. Lightroom data never overwrites data already set in the XMP sidecar file. It is recommended to have Lightroom write the XMP sidecar file before this script is run
-s, --strict | | Do strict check for Lightroom files and include the path into the check
-f, --field | Keyword: overwrite, location, city, state, country, countrycode | In the default no data is overwritten if it is already set. With the 'overwrite' flag all data is set new from the Google Maps location data. Other arguments are each of the location fields and if set only this field will be set. This can be combined with the 'overwrite' flag to overwrite already set data
-d, --fuzzy-cache | distance | Allow fuzzy cache lookup with either default value of 10m or an override value in m or km
-n, --nobackup | | Do not create a backup of XMP sidecar file when it is changed
-o, --openstreetmap | | Use OpenStreetMap instead of the default google maps
-e, --email | email address | For OpenStreetMap with a large number of access
@@ -51,26 +62,26 @@ Argument | Argument Value | Description
--debug | | Full detailed debug output. Will print out alot of data
--test | | Does not write any changed back to the XMP sidecar file. For testing purposes
The script will created a backup of the current sidecar file named <original name>.BK.xmp in the same location as the original file.
The script will created a backup of the current sidecar file named `<original name>.BK.xmp` in the same location as the original file.
If the Lightroom lookup is used without the --strict argument and several files with the same name are found, they will be skipped for usage.
#### Example
```
reverse_geolocate.py -i Photos/2017/01 -i Photos/2017/02 -l LightRoom/MyCatalogue -f overwrite -g <API KEY>
```sh
uv run reverse-geolocate -i Photos/2017/01 -i Photos/2017/02 -l LightRoom/MyCatalogue -f overwrite -g <API KEY>
```
Will find all XMP sidecar files in both folders *Photos/2017/01* and *Photos/2017/02* and all folder below it. Uses the Lightroom database at *LightRoom/MyCatalogue*. The script will overwrite all data, even if it is already set
```
reverse_geolocate.py -i Photos/2017/01 -i Photos/2017/02 -x Photos/2017/02/Folder\ A -x Photos/2017/01/Folder\ B/some_file.xmp -l LightRoom/MyCatalogue
```sh
uv run reverse-geolocate -i Photos/2017/01 -i Photos/2017/02 -x Photos/2017/02/Folder\ A -x Photos/2017/01/Folder\ B/some_file.xmp -l LightRoom/MyCatalogue
```
Will exlucde "Photos/2017/02/Folder A" from processing. For -x also a file (including the .xmp extension) can be given.
```
reverse_geolocate.py -i Photos/2017/01/Event-01/some_photo.xmp -f location
```sh
uv run reverse-geolocate -i Photos/2017/01/Event-01/some_photo.xmp -f location
```
Only works on *some_photo.xmp* file and will only set the *location* field if it is not yet set.
@@ -79,7 +90,7 @@ Only works on *some_photo.xmp* file and will only set the *location* field if it
The Google Maps API key and the OpenStreetMap Email address can be written to a config file with the -w argument. The config file is located in $HOME/.config/reverseGeolocate/reverse_geolocate.cfg in the following format
```
```ini
[API]
googleapikey = <google api key>
openstreetmapemail = <email>
@@ -87,6 +98,12 @@ openstreetmapemail = <email>
if no -g or -e flag is given the keys are read from the config file. If the -g or -e parameter is given it will override the one found in the config file. A new parameter can be written to this config file with -w parameter.
### Cache lookups
If the same GPS coordinate is detected no other API maps call is done. With the fuzzy-distance argument this can be further extended to certain distances for each GPS coordinate from each other. The default value is 10m and can be overriden with an value to the argument.
Can be used to force cache on GPS coordinates that are very close to each other but not exactly the same.
### Google data priority
Based in the JSON return data the following fields are set in order. If one can not be found for a target set, the next one below is used
@@ -122,22 +139,23 @@ order | type | target set
After the script is done the following overview will be printed
```
=======================================
XMP Files found : 57
Updated : 3
Skipped : 54
New GeoLocation from Map : 2
GeoLocation from Cache : 1
Failed reverse GeoLocate : 0
GeoLocaction from Lightroom : 1
No Lightroom data found : 46
More than one found in LR : 0
```txt
========================================
XMP Files found : 57
Updated : 3
Skipped : 54
New GeoLocation from Map : 2
GeoLocation from Cache : 1
GeoLocation from Fuzzy Cache : 0
Failed reverse GeoLocate : 0
GeoLocaction from Lightroom : 1
No Lightroom data found : 46
More than one found in LR : 0
```
If there are problems with getting data from the Google Maps API the complete errior sting will be printed
```
```txt
...
---> Photos/2017/02/some_file.xmp: Error in request: OVER_QUERY_LIMIT You have exceeded your daily request quota for this API. We recommend registering for a key at the Google Developers Console: https://console.developers.google.com/apis/credentials?project=_
(!) Could not geo loaction data [FAILED]
@@ -146,13 +164,13 @@ If there are problems with getting data from the Google Maps API the complete er
Also the files that could not be updated will be printed at the end of the run under the stats list
```
```txt
...
------------------------------
----------------------------------------
Files that failed to update:
Photos/2017/02/some_file.xmp
```
### Tested OS
This script has only been tested on macOS
This script has only been tested on macOS

File diff suppressed because it is too large Load Diff

17
pyproject.toml Normal file
View File

@@ -0,0 +1,17 @@
[project]
name = "reverse-geolocate"
version = "1.1.2"
description = "Reverse Geolocate from Lat/Long information and write location information into sidecard files"
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"python-xmp-toolkit>=2.1.0",
"requests>=2.32.5",
]
[project.scripts]
reverse-geolocate = "reverse_geolocate.reverse_geolocate:main"
[build-system]
requires = ["uv_build>=0.9.7,<0.10.0"]
build-backend = "uv_build"

View File

File diff suppressed because it is too large Load Diff